Fix 200 response exception builder

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-21 15:26:59 +08:00
parent 2f26b2ddb5
commit 9aff7d8f26
11 changed files with 81 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
common: common:
success: "00000"
error: error:
invalid_input: "00001" invalid_input: "00001"
unauthorized: "00002" unauthorized: "00002"

View File

@@ -113,5 +113,12 @@ func Exchange(c *gin.Context) {
RedirectUri string `json:"redirect_uri"` RedirectUri string `json:"redirect_uri"`
}{url.String()} }{url.String()}
utils.HttpResponse(c, 200, "", "success", exchangeResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusSuccess).
SetService(exception.ServiceAuth).
SetEndpoint(exception.EndpointAuthServiceExchange).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, exchangeResp)
} }

View File

@@ -118,5 +118,12 @@ func Magic(c *gin.Context) {
) )
} }
utils.HttpResponse(c, 200, "", "magic link sent") errorCode := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceAuth).
SetEndpoint(exception.EndpointAuthServiceMagic).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode)
} }

View File

@@ -64,5 +64,12 @@ func Refresh(c *gin.Context) {
RefreshToken string `json:"refresh_token"` RefreshToken string `json:"refresh_token"`
}{accessToken, refreshToken} }{accessToken, refreshToken}
utils.HttpResponse(c, 200, "", "success", tokenResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceAuth).
SetEndpoint(exception.EndpointAuthServiceRefresh).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, tokenResp)
} }

View File

@@ -83,5 +83,12 @@ func Token(c *gin.Context) {
RefreshToken string `json:"refresh_token"` RefreshToken string `json:"refresh_token"`
}{accessToken, refreshToken} }{accessToken, refreshToken}
utils.HttpResponse(c, 200, "", "success", tokenResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceAuth).
SetEndpoint(exception.EndpointAuthServiceToken).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, tokenResp)
} }

View File

@@ -196,5 +196,12 @@ func CheckinQuery(c *gin.Context) {
CheckinAt time.Time `json:"checkin_at"` CheckinAt time.Time `json:"checkin_at"`
}{attendance.CheckinAt} }{attendance.CheckinAt}
utils.HttpResponse(c, 200, "", "success", checkInAtResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceCheckinQuery).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, checkInAtResp)
} }

View File

@@ -60,5 +60,12 @@ func Info(c *gin.Context) {
EndTime time.Time `json:"end_time"` EndTime time.Time `json:"end_time"`
}{event.Name, event.StartTime, event.EndTime} }{event.Name, event.StartTime, event.EndTime}
utils.HttpResponse(c, 200, "", "success", eventInfoResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceInfo).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, eventInfoResp)
} }

View File

@@ -67,5 +67,12 @@ func Full(c *gin.Context) {
userFullResp := struct { userFullResp := struct {
UserTable *[]data.User `json:"user_table"` UserTable *[]data.User `json:"user_table"`
}{users} }{users}
utils.HttpResponse(c, 200, "", "success", userFullResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceUser).
SetEndpoint(exception.EndpointUserServiceFull).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, userFullResp)
} }

View File

@@ -63,5 +63,12 @@ func Info(c *gin.Context) {
PermissionLevel uint `json:"permission_level"` PermissionLevel uint `json:"permission_level"`
}{user.UserId, user.Email, user.Username, user.Nickname, user.Subtitle, user.Avatar, user.Bio, user.PermissionLevel} }{user.UserId, user.Email, user.Username, user.Nickname, user.Subtitle, user.Avatar, user.Bio, user.PermissionLevel}
utils.HttpResponse(c, 200, "", "success", userInfoResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceUser).
SetEndpoint(exception.EndpointUserServiceInfo).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, userInfoResp)
} }

View File

@@ -73,5 +73,12 @@ func List(c *gin.Context) {
userListResp := struct { userListResp := struct {
List *[]data.UserSearchDoc `json:"list"` List *[]data.UserSearchDoc `json:"list"`
}{list} }{list}
utils.HttpResponse(c, 200, "", "success", userListResp) errorCode := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceUser).
SetEndpoint(exception.EndpointUserServiceList).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode, userListResp)
} }

View File

@@ -159,5 +159,12 @@ func Update(c *gin.Context) {
// Update user info // Update user info
userData.UpdateByUserID(userId) userData.UpdateByUserID(userId)
utils.HttpResponse(c, 200, "", "success") errorCode := new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceUser).
SetEndpoint(exception.EndpointUserServiceUpdate).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
utils.HttpResponse(c, 200, errorCode)
} }