mirror of
				https://github.com/imgproxy/imgproxy.git
				synced 2025-10-30 23:08:02 +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 ( | ||||
| 	"net/http" | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/honeybadger-io/honeybadger-go" | ||||
|  | ||||
| 	"github.com/imgproxy/imgproxy/v3/config" | ||||
| 	"github.com/imgproxy/imgproxy/v3/ierrors" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| @@ -42,5 +44,11 @@ func Report(err error, req *http.Request, meta map[string]any) { | ||||
| 		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) | ||||
| 	} | ||||
|  | ||||
| 	eventID := hub.CaptureException(err) | ||||
| 	if eventID != nil { | ||||
| 		hub.Flush(timeout) | ||||
| 	// imgproxy wraps almost all errors into *ierrors.Error, so Sentry will show | ||||
| 	// the same error type for all errors. We need to fix it. | ||||
| 	// | ||||
| 	// 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