1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00

Mark downloading errors as unexpected

This commit is contained in:
DarthSim 2019-08-20 20:23:26 +06:00
parent 749924b2bd
commit de31ee50d8
2 changed files with 8 additions and 3 deletions

View File

@ -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)
@ -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)

View File

@ -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,