mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-21 22:54:48 +01:00
Merge pull request #146 from getAlby/bad-auth-sentry
Do not send bad auth errors to sentry
This commit is contained in:
@@ -44,7 +44,7 @@ func (controller *AuthController) Auth(c echo.Context) error {
|
|||||||
|
|
||||||
accessToken, refreshToken, err := controller.svc.GenerateToken(c.Request().Context(), body.Login, body.Password, body.RefreshToken)
|
accessToken, refreshToken, err := controller.svc.GenerateToken(c.Request().Context(), body.Login, body.Password, body.RefreshToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, responses.BadAuthError)
|
return c.JSON(http.StatusUnauthorized, responses.BadAuthError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, &AuthResponseBody{
|
return c.JSON(http.StatusOK, &AuthResponseBody{
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ func (suite *UserAuthTestSuite) TestAuthWithExpiredRefreshToken() {
|
|||||||
controller = controllers.NewAuthController(suite.Service)
|
controller = controllers.NewAuthController(suite.Service)
|
||||||
assert.NoError(suite.T(), controller.Auth(c))
|
assert.NoError(suite.T(), controller.Auth(c))
|
||||||
errorResponse := &responses.ErrorResponse{}
|
errorResponse := &responses.ErrorResponse{}
|
||||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
assert.Equal(suite.T(), http.StatusUnauthorized, rec.Code)
|
||||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
||||||
@@ -171,7 +171,7 @@ func (suite *UserAuthTestSuite) TestAuthWithInvalidSecretRefreshToken() {
|
|||||||
controller = controllers.NewAuthController(suite.Service)
|
controller = controllers.NewAuthController(suite.Service)
|
||||||
assert.NoError(suite.T(), controller.Auth(c))
|
assert.NoError(suite.T(), controller.Auth(c))
|
||||||
errorResponse := &responses.ErrorResponse{}
|
errorResponse := &responses.ErrorResponse{}
|
||||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
assert.Equal(suite.T(), http.StatusUnauthorized, rec.Code)
|
||||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
||||||
@@ -213,7 +213,7 @@ func (suite *UserAuthTestSuite) TestAuthWithInvalidUserIdRefreshToken() {
|
|||||||
controller = controllers.NewAuthController(suite.Service)
|
controller = controllers.NewAuthController(suite.Service)
|
||||||
assert.NoError(suite.T(), controller.Auth(c))
|
assert.NoError(suite.T(), controller.Auth(c))
|
||||||
errorResponse := &responses.ErrorResponse{}
|
errorResponse := &responses.ErrorResponse{}
|
||||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
assert.Equal(suite.T(), http.StatusUnauthorized, rec.Code)
|
||||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
||||||
@@ -249,7 +249,7 @@ func (suite *UserAuthTestSuite) TestAuthWithAccessToken() {
|
|||||||
controller = controllers.NewAuthController(suite.Service)
|
controller = controllers.NewAuthController(suite.Service)
|
||||||
assert.NoError(suite.T(), controller.Auth(c))
|
assert.NoError(suite.T(), controller.Auth(c))
|
||||||
errorResponse := &responses.ErrorResponse{}
|
errorResponse := &responses.ErrorResponse{}
|
||||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
assert.Equal(suite.T(), http.StatusUnauthorized, rec.Code)
|
||||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
||||||
@@ -270,7 +270,7 @@ func (suite *UserAuthTestSuite) TestAuthWithNotParseableRefreshToken() {
|
|||||||
controller := controllers.NewAuthController(suite.Service)
|
controller := controllers.NewAuthController(suite.Service)
|
||||||
assert.NoError(suite.T(), controller.Auth(c))
|
assert.NoError(suite.T(), controller.Auth(c))
|
||||||
errorResponse := &responses.ErrorResponse{}
|
errorResponse := &responses.ErrorResponse{}
|
||||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
assert.Equal(suite.T(), http.StatusUnauthorized, rec.Code)
|
||||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(errorResponse))
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
assert.Equal(suite.T(), responses.BadAuthError.Code, errorResponse.Code)
|
||||||
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
assert.Equal(suite.T(), responses.BadAuthError.Message, errorResponse.Message)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func Middleware(secret []byte) echo.MiddlewareFunc {
|
|||||||
config.SigningKey = secret
|
config.SigningKey = secret
|
||||||
config.ErrorHandlerWithContext = func(err error, c echo.Context) error {
|
config.ErrorHandlerWithContext = func(err error, c echo.Context) error {
|
||||||
c.Logger().Error(err)
|
c.Logger().Error(err)
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, echo.Map{
|
return echo.NewHTTPError(http.StatusUnauthorized, echo.Map{
|
||||||
"error": true,
|
"error": true,
|
||||||
"code": 1,
|
"code": 1,
|
||||||
"message": "bad auth",
|
"message": "bad auth",
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -94,7 +94,8 @@ func main() {
|
|||||||
// Setup exception tracking with Sentry if configured
|
// Setup exception tracking with Sentry if configured
|
||||||
if c.SentryDSN != "" {
|
if c.SentryDSN != "" {
|
||||||
if err = sentry.Init(sentry.ClientOptions{
|
if err = sentry.Init(sentry.ClientOptions{
|
||||||
Dsn: c.SentryDSN,
|
Dsn: c.SentryDSN,
|
||||||
|
IgnoreErrors: []string{"401"},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logger.Errorf("sentry init error: %v", err)
|
logger.Errorf("sentry init error: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user