don't log ERROR in ReportHandler when repo not found in cache

This commit is contained in:
Shawn Smith
2017-12-20 19:31:28 +09:00
parent 21e832bd3a
commit f9e6d61a37
2 changed files with 15 additions and 2 deletions

View File

@@ -14,6 +14,14 @@ import (
"github.com/gojp/goreportcard/download"
)
type notFoundError struct {
repo string
}
func (n notFoundError) Error() string {
return fmt.Sprintf("%q not found in cache", n.repo)
}
func dirName(repo string) string {
return fmt.Sprintf("_repos/src/%s", repo)
}
@@ -34,7 +42,7 @@ func getFromCache(repo string) (checksResp, error) {
}
cached := b.Get([]byte(repo))
if cached == nil {
return fmt.Errorf("%q not found in cache", repo)
return notFoundError{repo}
}
err = json.Unmarshal(cached, &resp)

View File

@@ -19,7 +19,12 @@ func ReportHandler(w http.ResponseWriter, r *http.Request, repo string, dev bool
resp, err := getFromCache(repo)
needToLoad := false
if err != nil {
log.Println("ERROR ReportHandler:", err) // log error, but continue
switch err.(type) {
case notFoundError:
// don't bother logging - we already log in getFromCache. continue
default:
log.Println("ERROR ReportHandler:", err) // log error, but continue
}
needToLoad = true
}