From 9cd0e38d853fca230011d3970e1f84732430447b Mon Sep 17 00:00:00 2001 From: hayato24s Date: Mon, 18 Mar 2024 21:48:48 +0900 Subject: [PATCH] WIP --- codegen/error/definition.py | 2 -- handler/api/rest/v3/course.go | 6 +++--- handler/common/interceptor/error_code_map_gen.go | 2 -- handler/common/middleware/echo.go | 4 ---- module/shared/err/code_gen.go | 2 -- 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/codegen/error/definition.py b/codegen/error/definition.py index 08a1f12..88964ad 100644 --- a/codegen/error/definition.py +++ b/codegen/error/definition.py @@ -37,9 +37,7 @@ ("ModuleNotFound", NotFound), ], "shared": [ - ("AlreadyExists", AlreadyExists), ("InvalidArgument", InvalidArgument), - ("NotFound", NotFound), ("Unauthenticated", Unauthenticated), ("Unauthorized", PermissionDenied), ], diff --git a/handler/api/rest/v3/course.go b/handler/api/rest/v3/course.go index f71e0f2..e3d1910 100644 --- a/handler/api/rest/v3/course.go +++ b/handler/api/rest/v3/course.go @@ -3,14 +3,14 @@ package restv3 import ( "context" "fmt" + "net/http" "strconv" "strings" - "github.com/twin-te/twinte-back/apperr" + "github.com/labstack/echo/v4" "github.com/twin-te/twinte-back/base" "github.com/twin-te/twinte-back/handler/api/rest/v3/openapi" shareddomain "github.com/twin-te/twinte-back/module/shared/domain" - sharederr "github.com/twin-te/twinte-back/module/shared/err" timetablemodule "github.com/twin-te/twinte-back/module/timetable" timetabledomain "github.com/twin-te/twinte-back/module/timetable/domain" ) @@ -328,7 +328,7 @@ func (h *impl) GetCoursesYearCode(ctx context.Context, request openapi.GetCourse } if len(courses) == 0 { - return nil, apperr.New(sharederr.CodeNotFound, "") + return nil, echo.NewHTTPError(http.StatusNotFound, "not found course") } apiCourse, err := toApiCourse(courses[0]) diff --git a/handler/common/interceptor/error_code_map_gen.go b/handler/common/interceptor/error_code_map_gen.go index f6eae5c..3a7ecf5 100644 --- a/handler/common/interceptor/error_code_map_gen.go +++ b/handler/common/interceptor/error_code_map_gen.go @@ -25,9 +25,7 @@ var AppErrorCodeToConnectErrorCode = map[apperr.Code]connect.Code{ schoolcalendarerr.CodeModuleNotFound: connect.CodeNotFound, - sharederr.CodeAlreadyExists: connect.CodeAlreadyExists, sharederr.CodeInvalidArgument: connect.CodeInvalidArgument, - sharederr.CodeNotFound: connect.CodeNotFound, sharederr.CodeUnauthenticated: connect.CodeUnauthenticated, sharederr.CodeUnauthorized: connect.CodePermissionDenied, diff --git a/handler/common/middleware/echo.go b/handler/common/middleware/echo.go index 3804747..c28c221 100644 --- a/handler/common/middleware/echo.go +++ b/handler/common/middleware/echo.go @@ -24,16 +24,12 @@ func NewEchoErrorHandler() func(echo.HandlerFunc) echo.HandlerFunc { if aerr, ok := apperr.As(err); ok { switch aerr.Code { - case sharederr.CodeAlreadyExists: - return echo.NewHTTPError(http.StatusConflict, aerr.Message) case sharederr.CodeInvalidArgument: return echo.NewHTTPError(http.StatusBadRequest, aerr.Message) case sharederr.CodeUnauthenticated: return echo.ErrUnauthorized case sharederr.CodeUnauthorized: return echo.ErrForbidden - case sharederr.CodeNotFound: - return echo.NewHTTPError(http.StatusNotFound, aerr.Message) } } diff --git a/module/shared/err/code_gen.go b/module/shared/err/code_gen.go index e483bcb..631c2f6 100644 --- a/module/shared/err/code_gen.go +++ b/module/shared/err/code_gen.go @@ -5,9 +5,7 @@ package sharederr import "github.com/twin-te/twinte-back/apperr" const ( - CodeAlreadyExists apperr.Code = "shared.AlreadyExists" CodeInvalidArgument apperr.Code = "shared.InvalidArgument" - CodeNotFound apperr.Code = "shared.NotFound" CodeUnauthenticated apperr.Code = "shared.Unauthenticated" CodeUnauthorized apperr.Code = "shared.Unauthorized" )