Просмотр исходного кода

Fix reporting image loading errors

DarthSim 1 год назад
Родитель
Сommit
a020a7603e
3 измененных файлов с 8 добавлено и 3 удалено
  1. 3 0
      CHANGELOG.md
  2. 1 1
      router/logging.go
  3. 4 2
      vips/vips.go

+ 3 - 0
CHANGELOG.md

@@ -5,6 +5,9 @@
 - Don't report `The image request is cancelled` errors.
 - (pro) Change the `/info` endpoint behavior to return only the first EXIF/XMP/IPTC block data of JPEG if the image contains multiple metadata blocks of the same type.
 
+### Fix
+- Fix reporting image loading errors.
+
 ### Fix
 - Fix the `Cache-Control` and `Expires` headers behavior when both `IMGPROXY_CACHE_CONTROL_PASSTHROUGH` and `IMGPROXY_FALLBACK_IMAGE_TTL` configs are set.
 - (pro) Fix the `IMGPROXY_FALLBACK_IMAGE_TTL` config behavior when the `fallback_image_url` processing option is used.

+ 1 - 1
router/logging.go

@@ -24,7 +24,7 @@ func LogResponse(reqID string, r *http.Request, status int, err *ierrors.Error,
 	var level log.Level
 
 	switch {
-	case status >= 500:
+	case status >= 500 || (err != nil && err.Unexpected):
 		level = log.ErrorLevel
 	case status >= 400:
 		level = log.WarnLevel

+ 4 - 2
vips/vips.go

@@ -155,12 +155,14 @@ func Error() error {
 	defer C.vips_error_clear()
 
 	errstr := strings.TrimSpace(C.GoString(C.vips_error_buffer()))
+	err := ierrors.NewUnexpected(errstr, 1)
 
 	if strings.Contains(errstr, "load_buffer: ") {
-		return ierrors.New(422, errstr, "Broken or unsupported image")
+		err.StatusCode = 422
+		err.PublicMessage = "Broken or unsupported image"
 	}
 
-	return ierrors.NewUnexpected(errstr, 1)
+	return err
 }
 
 func hasOperation(name string) bool {