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:
@@ -116,7 +116,7 @@ func checkTypeAndDimensions(r io.Reader) (imageType, error) {
|
|||||||
return imageTypeUnknown, errSourceImageTypeNotSupported
|
return imageTypeUnknown, errSourceImageTypeNotSupported
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return imageTypeUnknown, newUnexpectedError(err.Error(), 0)
|
return imageTypeUnknown, wrapError(err, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
imgtype, imgtypeOk := imageTypes[meta.Format()]
|
imgtype, imgtypeOk := imageTypes[meta.Format()]
|
||||||
|
@@ -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 {
|
func callers(skip int) []uintptr {
|
||||||
stack := make([]uintptr, 10)
|
stack := make([]uintptr, 10)
|
||||||
n := runtime.Callers(skip, stack)
|
n := runtime.Callers(skip, stack)
|
||||||
|
@@ -102,14 +102,7 @@ func withSecret(h routeHandler) routeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlePanic(reqID string, rw http.ResponseWriter, r *http.Request, err error) {
|
func handlePanic(reqID string, rw http.ResponseWriter, r *http.Request, err error) {
|
||||||
var (
|
ierr := wrapError(err, 3)
|
||||||
ierr *imgproxyError
|
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
|
|
||||||
if ierr, ok = err.(*imgproxyError); !ok {
|
|
||||||
ierr = newUnexpectedError(err.Error(), 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ierr.Unexpected {
|
if ierr.Unexpected {
|
||||||
reportError(err, r)
|
reportError(err, r)
|
||||||
|
Reference in New Issue
Block a user