Add context for all exceptions

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-21 19:37:20 +08:00
parent 154c929859
commit 986f63c0af
16 changed files with 91 additions and 87 deletions

View File

@@ -18,7 +18,7 @@ func Full(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceFull).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorMissingUserId).
Build()
Build(c)
utils.HttpResponse(c, 403, errorCode)
return
}
@@ -31,7 +31,7 @@ func Full(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorUuidParseFailed).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 500, errorCode)
return
}
@@ -45,7 +45,7 @@ func Full(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorUserNotFound).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 404, errorCode)
return
}
@@ -59,7 +59,7 @@ func Full(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorDatabase).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 500, errorCode)
return
}
@@ -73,6 +73,6 @@ func Full(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceFull).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
Build(c)
utils.HttpResponse(c, 200, errorCode, userFullResp)
}

View File

@@ -19,7 +19,7 @@ func Info(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceInfo).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorMissingUserId).
Build()
Build(c)
utils.HttpResponse(c, 403, errorCode)
return
}
@@ -32,7 +32,7 @@ func Info(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorUuidParseFailed).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 500, errorCode)
return
}
@@ -47,7 +47,7 @@ func Info(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorUserNotFound).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 404, errorCode)
return
}
@@ -69,6 +69,6 @@ func Info(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceInfo).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
Build(c)
utils.HttpResponse(c, 200, errorCode, userInfoResp)
}

View File

@@ -23,7 +23,7 @@ func List(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceList).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -38,7 +38,7 @@ func List(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -51,7 +51,7 @@ func List(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -66,7 +66,7 @@ func List(c *gin.Context) {
SetType(exception.TypeSpecific).
SetOriginal(exception.UserListMeilisearchFailed).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 500, errorCode)
}
@@ -79,6 +79,6 @@ func List(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceList).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
Build(c)
utils.HttpResponse(c, 200, errorCode, userListResp)
}

View File

@@ -22,7 +22,7 @@ func Update(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceUpdate).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorMissingUserId).
Build()
Build(c)
utils.HttpResponse(c, 403, errorCode)
return
}
@@ -35,7 +35,7 @@ func Update(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorUuidParseFailed).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 500, errorCode)
return
}
@@ -50,7 +50,7 @@ func Update(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -65,7 +65,7 @@ func Update(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorUserNotFound).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 500, errorCode)
return
}
@@ -87,7 +87,7 @@ func Update(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceUpdate).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -102,7 +102,7 @@ func Update(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceUpdate).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -117,7 +117,7 @@ func Update(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceUpdate).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -134,7 +134,7 @@ func Update(c *gin.Context) {
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(err).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -149,7 +149,7 @@ func Update(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceUpdate).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
Build()
Build(c)
utils.HttpResponse(c, 400, errorCode)
return
}
@@ -165,6 +165,6 @@ func Update(c *gin.Context) {
SetEndpoint(exception.EndpointUserServiceUpdate).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
Build()
Build(c)
utils.HttpResponse(c, 200, errorCode)
}