mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-23 07:35:04 +01:00
Simple way to filter out bad auth from sentry
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package responses
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
@@ -43,7 +44,7 @@ func HTTPErrorHandler(err error, c echo.Context) {
|
||||
return
|
||||
}
|
||||
c.Logger().Error(err)
|
||||
if hub := sentryecho.GetHubFromContext(c); hub != nil {
|
||||
if hub := sentryecho.GetHubFromContext(c); hub != nil && isErrResponseAllowedForSentry(errToErrorResponse(err)) {
|
||||
hub.WithScope(func(scope *sentry.Scope) {
|
||||
scope.SetExtra("UserID", c.Get("UserID"))
|
||||
hub.CaptureException(err)
|
||||
@@ -58,3 +59,30 @@ func HTTPErrorHandler(err error, c echo.Context) {
|
||||
}
|
||||
// TODO: use an error matching the error code
|
||||
}
|
||||
|
||||
// this is a simple way to try to convert err.Message interface to ErrorResponse
|
||||
// without external packages
|
||||
func errToErrorResponse(err error) *ErrorResponse {
|
||||
he, ok := err.(*echo.HTTPError)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
heJson, err := json.Marshal(he.Message)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
heBadResponse := &ErrorResponse{}
|
||||
err = json.Unmarshal(heJson, heBadResponse)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return heBadResponse
|
||||
}
|
||||
|
||||
// currently only bad auth errors are not allowed
|
||||
func isErrResponseAllowedForSentry(errResponse *ErrorResponse) bool {
|
||||
return errResponse != nil && errResponse.Code != BadAuthError.Code
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user