more specific error handling
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
d6a8abad00
commit
7bba18b47b
@ -2,6 +2,7 @@ package recipe
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -665,13 +666,21 @@ func CheckoutDefaultBranch(repo *git.Repository, recipeName string) (plumbing.Re
|
|||||||
return branch, nil
|
return branch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CatalogueOfflineError struct {
|
||||||
|
msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *CatalogueOfflineError) Error() string {
|
||||||
|
return fmt.Sprintf("catalogue offline: %s", e.msg)
|
||||||
|
}
|
||||||
|
|
||||||
// recipeCatalogueFSIsLatest checks whether the recipe catalogue stored locally
|
// recipeCatalogueFSIsLatest checks whether the recipe catalogue stored locally
|
||||||
// is up to date.
|
// is up to date.
|
||||||
func recipeCatalogueFSIsLatest() (bool, error) {
|
func recipeCatalogueFSIsLatest() (bool, error) {
|
||||||
httpClient := web.NewHTTPRetryClient()
|
httpClient := web.NewHTTPRetryClient()
|
||||||
res, err := httpClient.Head(RecipeCatalogueURL)
|
res, err := httpClient.Head(RecipeCatalogueURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, &CatalogueOfflineError{err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastModified := res.Header["Last-Modified"][0]
|
lastModified := res.Header["Last-Modified"][0]
|
||||||
@ -712,17 +721,21 @@ func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
|||||||
|
|
||||||
recipeFSIsLatest, err := recipeCatalogueFSIsLatest()
|
recipeFSIsLatest, err := recipeCatalogueFSIsLatest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
var offlineErr *CatalogueOfflineError
|
||||||
logrus.Error("failed to access last recipe catalogue")
|
if errors.As(err, &offlineErr) {
|
||||||
|
logrus.Error(err)
|
||||||
|
logrus.Error("unable to retrieve catalogue from internet, using local copy.")
|
||||||
|
recipeFSIsLatest = true
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !recipeFSIsLatest {
|
if !recipeFSIsLatest {
|
||||||
if err := readRecipeCatalogueWeb(&recipes); err != nil {
|
if err := readRecipeCatalogueWeb(&recipes); err != nil {
|
||||||
logrus.Error(err)
|
return nil, err
|
||||||
logrus.Error("failed to access web recipe catalogue")
|
|
||||||
} else {
|
|
||||||
return recipes, nil
|
|
||||||
}
|
}
|
||||||
|
return recipes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := readRecipeCatalogueFS(&recipes); err != nil {
|
if err := readRecipeCatalogueFS(&recipes); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user