Files
pulse/internal/monitoring/backup_guard.go
T
pulse-triage[bot] c3b28f4557 fix(pbs): classify backup cache failures by HTTP status
A gateway body quoting API error 403 must not discard cached backups. Use the client's typed response status before legacy text fallback; cover gateway failures and genuine terminal responses.

Change-source: pulse-maintainer
2026-09-05 15:05:53 +01:00

33 lines
951 B
Go

package monitoring
import (
"strings"
"github.com/rcourtman/pulse-go-rewrite/pkg/pbs"
)
// shouldPreservePBSBackupsWithTerminal preserves stale PBS backups only when all
// datastore fetches failed and at least one failure was non-terminal.
func shouldPreservePBSBackupsWithTerminal(datastoreCount, datastoreFetches, datastoreTerminalFailure int) bool {
if datastoreCount > 0 && datastoreFetches == 0 && datastoreTerminalFailure < datastoreCount {
return true
}
return false
}
// shouldReuseCachedPBSBackups keeps cached data for transient fetch errors and
// avoids reuse for terminal API 4xx errors.
func shouldReuseCachedPBSBackups(err error) bool {
if err == nil {
return false
}
if status, ok := pbs.HTTPStatus(err); ok {
return status < 400 || status >= 500
}
// Retain compatibility with untyped errors from older callers.
if strings.Contains(strings.ToLower(err.Error()), "api error 4") {
return false
}
return true
}