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

More clear downloading timeout errors; Add image URL to fallback image usage warning

This commit is contained in:
DarthSim 2021-06-28 14:35:01 +06:00
parent 302bf64ea2
commit 56858a3692
3 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,9 @@
# Changelog
## [Unreleased]
### Change
- More clear downloading errors.
### Fix
- Fix ICC profile handling in some cases.

View File

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

View File

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