mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Improve index updating error handling
This commit is contained in:
parent
2fe8f38ac8
commit
8889e70c8b
1 changed files with 12 additions and 6 deletions
|
@ -15,20 +15,26 @@ import (
|
||||||
"github.com/safing/portbase/log"
|
"github.com/safing/portbase/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateIndexes downloads all indexes and returns the first error encountered.
|
// UpdateIndexes downloads all indexes. An error is only returned when all
|
||||||
|
// indexes fail to update.
|
||||||
func (reg *ResourceRegistry) UpdateIndexes(ctx context.Context) error {
|
func (reg *ResourceRegistry) UpdateIndexes(ctx context.Context) error {
|
||||||
var firstErr error
|
var lastErr error
|
||||||
|
var anySuccess bool
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
for _, idx := range reg.getIndexes() {
|
for _, idx := range reg.getIndexes() {
|
||||||
if err := reg.downloadIndex(ctx, client, idx); err != nil {
|
if err := reg.downloadIndex(ctx, client, idx); err != nil {
|
||||||
if firstErr == nil {
|
lastErr = err
|
||||||
firstErr = err
|
log.Warningf("%s: failed to update index %s: %s", reg.Name, idx.Path, err)
|
||||||
}
|
} else {
|
||||||
|
anySuccess = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return firstErr
|
if !anySuccess {
|
||||||
|
return fmt.Errorf("failed to update all indexes, last error was: %s", lastErr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reg *ResourceRegistry) downloadIndex(ctx context.Context, client *http.Client, idx Index) error {
|
func (reg *ResourceRegistry) downloadIndex(ctx context.Context, client *http.Client, idx Index) error {
|
||||||
|
|
Loading…
Add table
Reference in a new issue