1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/vips/errors.go
Sergei Aleksandrovich e33254005d Refactored errors (#1578)
* Refactored errors

* Make monitoring and errorreport accept `errctx.Error` instead of `error`

* Add server.Error; Remove category from errctx; Make HTTP handlers respond with *server.Error

* Remove stackSkip from errctx.Wrap; Add errctx.WrapWithStackSkip
2025-11-20 01:26:21 +06:00

34 lines
685 B
Go

package vips
import (
"net/http"
"regexp"
"github.com/imgproxy/imgproxy/v3/errctx"
)
var badImageErrRe = []*regexp.Regexp{
regexp.MustCompile(`^(\S+)load_source: `),
regexp.MustCompile(`^VipsJpeg: `),
regexp.MustCompile(`^tiff2vips: `),
regexp.MustCompile(`^webp2vips: `),
}
type VipsError struct{ *errctx.TextError }
func newVipsError(msg string) error {
var opts []errctx.Option
for _, re := range badImageErrRe {
if re.MatchString(msg) {
opts = []errctx.Option{
errctx.WithStatusCode(http.StatusUnprocessableEntity),
errctx.WithPublicMessage("Broken or unsupported image"),
}
break
}
}
return VipsError{errctx.NewTextError(msg, 1, opts...)}
}