mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-01-08 10:45:04 +02:00
Report only unexpected errors
This commit is contained in:
parent
7f95569dcf
commit
98ad26644e
@ -6,7 +6,8 @@
|
||||
- `SO_REUSEPORT` socker option support. Can be enabled with `IMGPROXY_SO_REUSEPORT`;
|
||||
- `dpr` option always changes the resulting size even if it leads to enlarge and `enlarge` is falsey;
|
||||
- Log to STDOUT;
|
||||
- [filename](./docs/generating_the_url_advanced.md#filename) option.
|
||||
- [filename](./docs/generating_the_url_advanced.md#filename) option;
|
||||
- Only unexpected errors are reported to Bugsnag/Honeybadger/Sentry.
|
||||
|
||||
## v2.3.0
|
||||
|
||||
|
14
errors.go
14
errors.go
@ -10,6 +10,7 @@ type imgproxyError struct {
|
||||
StatusCode int
|
||||
Message string
|
||||
PublicMessage string
|
||||
Unexpected bool
|
||||
}
|
||||
|
||||
func (e *imgproxyError) Error() string {
|
||||
@ -17,14 +18,19 @@ func (e *imgproxyError) Error() string {
|
||||
}
|
||||
|
||||
func newError(status int, msg string, pub string) *imgproxyError {
|
||||
return &imgproxyError{status, msg, pub}
|
||||
return &imgproxyError{
|
||||
StatusCode: status,
|
||||
Message: msg,
|
||||
PublicMessage: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func newUnexpectedError(msg string, skip int) *imgproxyError {
|
||||
return &imgproxyError{
|
||||
500,
|
||||
fmt.Sprintf("Unexpected error: %s\n%s", msg, stacktrace(skip+3)),
|
||||
"Internal error",
|
||||
StatusCode: 500,
|
||||
Message: fmt.Sprintf("Unexpected error: %s\n%s", msg, stacktrace(skip+3)),
|
||||
PublicMessage: "Internal error",
|
||||
Unexpected: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,8 +96,6 @@ func withSecret(h routeHandler) routeHandler {
|
||||
}
|
||||
|
||||
func handlePanic(reqID string, rw http.ResponseWriter, r *http.Request, err error) {
|
||||
reportError(err, r)
|
||||
|
||||
var (
|
||||
ierr *imgproxyError
|
||||
ok bool
|
||||
@ -107,6 +105,10 @@ func handlePanic(reqID string, rw http.ResponseWriter, r *http.Request, err erro
|
||||
ierr = newUnexpectedError(err.Error(), 3)
|
||||
}
|
||||
|
||||
if ierr.Unexpected {
|
||||
reportError(err, r)
|
||||
}
|
||||
|
||||
logResponse(reqID, ierr.StatusCode, ierr.Message)
|
||||
|
||||
rw.WriteHeader(ierr.StatusCode)
|
||||
|
Loading…
Reference in New Issue
Block a user