Skip to content

Commit

Permalink
refactor: revise extauth status code
Browse files Browse the repository at this point in the history
  • Loading branch information
tithanayut committed Feb 15, 2025
1 parent 77a879d commit 85d1fa0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions auth/server-session/handler/extauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *Server) ExtAuth(c echo.Context) error {
if err != nil {
l.Info().Err(err).Msg("[Server.ExtAuth] session cookie not found")

return response.Unauthorized(c, "no session")
return response.Status(c, http.StatusUnauthorized)
}

userID, err := s.service.VerifySession(ctx, sessionID.Value)
Expand All @@ -49,11 +49,11 @@ func (s *Server) ExtAuth(c echo.Context) error {
}
c.SetCookie(cookie)

return response.Unauthorized(c, "invalid session")
return response.Status(c, http.StatusUnauthorized)
default:
l.Error().Err(err).Msg("[Server.ExtAuth] failed to verify session")

return response.InternalServerError(c, "failed to verify session")
return response.Status(c, http.StatusInternalServerError)
}
}

Expand All @@ -62,5 +62,5 @@ func (s *Server) ExtAuth(c echo.Context) error {

l.Info().Str("userId", userID).Msg("[Server.ExtAuth] session verified")

return response.Ok(c, "ok")
return response.Status(c, http.StatusOK)
}
4 changes: 4 additions & 0 deletions pkg/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func Success(c echo.Context) error {
return c.NoContent(http.StatusNoContent)
}

func Status(c echo.Context, status int) error {
return c.NoContent(status)
}

func Error(c echo.Context, status int, msg string) error {
res := ErrorResponse{
Error: msg,
Expand Down

0 comments on commit 85d1fa0

Please sign in to comment.