mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-25 13:10:03 +00:00
c3b28f4557
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
33 lines
951 B
Go
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
|
|
}
|