diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a39351a..e775879f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## [Unreleased] +### Change +- More clear downloading errors. + ### Fix - Fix ICC profile handling in some cases. diff --git a/download.go b/download.go index 46df4bc1..d08dae8f 100644 --- a/download.go +++ b/download.go @@ -4,6 +4,7 @@ import ( "compress/gzip" "context" "crypto/tls" + "errors" "fmt" "io" "io/ioutil" @@ -100,6 +101,17 @@ func initDownloading() error { return nil } +type httpError interface { + Timeout() bool +} + +func checkTimeoutErr(err error) error { + if httpErr, ok := err.(httpError); ok && httpErr.Timeout() { + return errors.New("The image request timed out") + } + return err +} + func checkDimensions(width, height int) error { if conf.MaxSrcDimension > 0 && (width > conf.MaxSrcDimension || height > conf.MaxSrcDimension) { return errSourceDimensionsTooBig @@ -118,7 +130,7 @@ func checkTypeAndDimensions(r io.Reader) (imageType, error) { return imageTypeUnknown, errSourceImageTypeNotSupported } if err != nil { - return imageTypeUnknown, newUnexpectedError(err.Error(), 0) + return imageTypeUnknown, newUnexpectedError(checkTimeoutErr(err).Error(), 0) } imgtype, imgtypeOk := imageTypes[meta.Format()] @@ -153,7 +165,7 @@ func readAndCheckImage(r io.Reader, contentLength int) (*imageData, error) { if _, err = buf.ReadFrom(r); err != nil { cancel() - return nil, newError(404, err.Error(), msgSourceImageIsUnreachable) + return nil, newError(404, checkTimeoutErr(err).Error(), msgSourceImageIsUnreachable) } return &imageData{buf.Bytes(), imgtype, cancel}, nil @@ -169,7 +181,7 @@ func requestImage(imageURL string) (*http.Response, error) { res, err := downloadClient.Do(req) if err != nil { - return res, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors) + return res, newError(404, checkTimeoutErr(err).Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors) } if res.StatusCode != 200 { diff --git a/processing_handler.go b/processing_handler.go index 3fee11cb..96f296cc 100644 --- a/processing_handler.go +++ b/processing_handler.go @@ -185,7 +185,7 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) { reportError(err, r) } - logWarning("Could not load image. Using fallback image: %s", err.Error()) + logWarning("Could not load image %s. Using fallback image. %s", getImageURL(ctx), err.Error()) ctx = context.WithValue(ctx, imageDataCtxKey, fallbackImage) }