aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/api/handlers.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-01 21:11:12 +0900
committernsfisis <nsfisis@gmail.com>2024-08-01 21:11:12 +0900
commitd4b76effa883fc191b82027e7d76d1f34fcc2992 (patch)
tree7cf594ef1cac367f1ffba384a8508ade8e39bd0e /backend/api/handlers.go
parentebb1129ae9ef16139a32bf899d42009176642299 (diff)
downloadiosdc-japan-2025-albatross-d4b76effa883fc191b82027e7d76d1f34fcc2992.tar.gz
iosdc-japan-2025-albatross-d4b76effa883fc191b82027e7d76d1f34fcc2992.tar.zst
iosdc-japan-2025-albatross-d4b76effa883fc191b82027e7d76d1f34fcc2992.zip
refactor: simplify error responses in OpenAPI spec
Diffstat (limited to 'backend/api/handlers.go')
-rw-r--r--backend/api/handlers.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/backend/api/handlers.go b/backend/api/handlers.go
index 26f7a7d..35fc9f7 100644
--- a/backend/api/handlers.go
+++ b/backend/api/handlers.go
@@ -66,7 +66,9 @@ func (h *ApiHandler) AdminGetGame(ctx context.Context, request AdminGetGameReque
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return AdminGetGame404JSONResponse{
- Message: "Game not found",
+ NotFoundJSONResponse: NotFoundJSONResponse{
+ Message: "Game not found",
+ },
}, nil
} else {
return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error())
@@ -113,7 +115,9 @@ func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameReque
if err != nil {
if err == pgx.ErrNoRows {
return AdminPutGame404JSONResponse{
- Message: "Game not found",
+ NotFoundJSONResponse: NotFoundJSONResponse{
+ Message: "Game not found",
+ },
}, nil
} else {
return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error())
@@ -175,7 +179,9 @@ func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameReque
})
if err != nil {
return AdminPutGame400JSONResponse{
- Message: err.Error(),
+ BadRequestJSONResponse: BadRequestJSONResponse{
+ Message: err.Error(),
+ },
}, nil
}
@@ -208,14 +214,18 @@ func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObje
userID, err := auth.Login(ctx, h.q, username, password)
if err != nil {
return PostLogin401JSONResponse{
- Message: "Invalid username or password",
+ UnauthorizedJSONResponse: UnauthorizedJSONResponse{
+ Message: "Invalid username or password",
+ },
}, nil
}
user, err := h.q.GetUserById(ctx, int32(userID))
if err != nil {
return PostLogin401JSONResponse{
- Message: "Invalid username or password",
+ UnauthorizedJSONResponse: UnauthorizedJSONResponse{
+ Message: "Invalid username or password",
+ },
}, nil
}
@@ -283,7 +293,9 @@ func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject,
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return GetGame404JSONResponse{
- Message: "Game not found",
+ NotFoundJSONResponse: NotFoundJSONResponse{
+ Message: "Game not found",
+ },
}, nil
} else {
return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error())