Skip to content

Commit

Permalink
Mark downloading errors as unexpected
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthSim committed Aug 20, 2019
1 parent 749924b commit de31ee5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func downloadImage(ctx context.Context) (context.Context, context.CancelFunc, er

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return ctx, func() {}, newError(404, err.Error(), msgSourceImageIsUnreachable)
return ctx, func() {}, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected()
}

req.Header.Set("User-Agent", conf.UserAgent)
Expand All @@ -181,13 +181,13 @@ func downloadImage(ctx context.Context) (context.Context, context.CancelFunc, er
defer res.Body.Close()
}
if err != nil {
return ctx, func() {}, newError(404, err.Error(), msgSourceImageIsUnreachable)
return ctx, func() {}, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected()
}

if res.StatusCode != 200 {
body, _ := ioutil.ReadAll(res.Body)
msg := fmt.Sprintf("Can't download image; Status: %d; %s", res.StatusCode, string(body))
return ctx, func() {}, newError(404, msg, msgSourceImageIsUnreachable)
return ctx, func() {}, newError(404, msg, msgSourceImageIsUnreachable).MarkAsUnexpected()
}

return readAndCheckImage(ctx, res)
Expand Down
5 changes: 5 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func (e *imgproxyError) StackTrace() []uintptr {
return e.stack
}

func (e *imgproxyError) MarkAsUnexpected() *imgproxyError {
e.Unexpected = true
return e
}

func newError(status int, msg string, pub string) *imgproxyError {
return &imgproxyError{
StatusCode: status,
Expand Down

0 comments on commit de31ee5

Please sign in to comment.