mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-28 12:37:47 +02:00
Replace *ierrors.Error
with actual data type in Sentry and Honeybadger integrations
This commit is contained in:
@@ -2,11 +2,13 @@ package honeybadger
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/honeybadger-io/honeybadger-go"
|
"github.com/honeybadger-io/honeybadger-go"
|
||||||
|
|
||||||
"github.com/imgproxy/imgproxy/v3/config"
|
"github.com/imgproxy/imgproxy/v3/config"
|
||||||
|
"github.com/imgproxy/imgproxy/v3/ierrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -42,5 +44,11 @@ func Report(err error, req *http.Request, meta map[string]any) {
|
|||||||
extra[key] = v
|
extra[key] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
honeybadger.Notify(err, req.URL, extra)
|
hbErr := honeybadger.NewError(err)
|
||||||
|
|
||||||
|
if e, ok := err.(*ierrors.Error); ok {
|
||||||
|
hbErr.Class = reflect.TypeOf(e.Unwrap()).String()
|
||||||
|
}
|
||||||
|
|
||||||
|
honeybadger.Notify(hbErr, req.URL, extra)
|
||||||
}
|
}
|
||||||
|
@@ -40,8 +40,22 @@ func Report(err error, req *http.Request, meta map[string]any) {
|
|||||||
hub.Scope().SetContext("Processing context", meta)
|
hub.Scope().SetContext("Processing context", meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
eventID := hub.CaptureException(err)
|
// imgproxy wraps almost all errors into *ierrors.Error, so Sentry will show
|
||||||
if eventID != nil {
|
// the same error type for all errors. We need to fix it.
|
||||||
hub.Flush(timeout)
|
//
|
||||||
|
// Instead of using hub.CaptureException(err), we need to create an event
|
||||||
|
// manually and replace `*ierrors.Error` with the wrapped error type
|
||||||
|
// (which is the previous exception type in the exception chain).
|
||||||
|
if event := hub.Client().EventFromException(err, sentry.LevelError); event != nil {
|
||||||
|
for i := 1; i < len(event.Exception); i++ {
|
||||||
|
if event.Exception[i].Type == "*ierrors.Error" {
|
||||||
|
event.Exception[i].Type = event.Exception[i-1].Type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eventID := hub.CaptureEvent(event)
|
||||||
|
if eventID != nil {
|
||||||
|
hub.Flush(timeout)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user