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:
parent
749924b2bd
commit
de31ee50d8
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user