1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-09-16 09:36:18 +02:00

Better imgproxyError handling

This commit is contained in:
DarthSim
2021-03-22 22:45:37 +06:00
parent cfe9578f50
commit 08b70d8b91
3 changed files with 9 additions and 9 deletions

View File

@@ -116,7 +116,7 @@ func checkTypeAndDimensions(r io.Reader) (imageType, error) {
return imageTypeUnknown, errSourceImageTypeNotSupported
}
if err != nil {
return imageTypeUnknown, newUnexpectedError(err.Error(), 0)
return imageTypeUnknown, wrapError(err, 0)
}
imgtype, imgtypeOk := imageTypes[meta.Format()]

View File

@@ -55,6 +55,13 @@ func newUnexpectedError(msg string, skip int) *imgproxyError {
}
}
func wrapError(err error, skip int) *imgproxyError {
if ierr, ok := err.(*imgproxyError); ok {
return ierr
}
return newUnexpectedError(err.Error(), skip+1)
}
func callers(skip int) []uintptr {
stack := make([]uintptr, 10)
n := runtime.Callers(skip, stack)

View File

@@ -102,14 +102,7 @@ func withSecret(h routeHandler) routeHandler {
}
func handlePanic(reqID string, rw http.ResponseWriter, r *http.Request, err error) {
var (
ierr *imgproxyError
ok bool
)
if ierr, ok = err.(*imgproxyError); !ok {
ierr = newUnexpectedError(err.Error(), 3)
}
ierr := wrapError(err, 3)
if ierr.Unexpected {
reportError(err, r)