This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 04aef2e2a Dev fix tapd (#7339)
04aef2e2a is described below
commit 04aef2e2a3018f1a87c84d6bec4f934d166301c1
Author: Lynwee <[email protected]>
AuthorDate: Wed Apr 17 13:52:34 2024 +0800
Dev fix tapd (#7339)
* fix(tapd): change iteration_id's type from uint64 to int64
* fix(tapd): fix test
* feat(backend): add code field in resp body
---
backend/server/api/shared/api_output.go | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/backend/server/api/shared/api_output.go
b/backend/server/api/shared/api_output.go
index fb8cace6f..debbe0a0e 100644
--- a/backend/server/api/shared/api_output.go
+++ b/backend/server/api/shared/api_output.go
@@ -31,6 +31,7 @@ import (
const BadRequestBody = "bad request body format"
type TypedApiBody[T any] struct {
+ Code int `json:"code"`
Success bool `json:"success"`
Message string `json:"message"`
Causes []string `json:"causes"`
@@ -44,6 +45,28 @@ type ResponsePipelines struct {
Pipelines []*models.Pipeline `json:"pipelines"`
}
+// ApiOutputErrorWithCustomCode writes a JSON error message to the HTTP
response body
+func ApiOutputErrorWithCustomCode(c *gin.Context, code int, err error) {
+ if e, ok := err.(errors.Error); ok {
+ logruslog.Global.Error(err, "HTTP %d error",
e.GetType().GetHttpCode())
+ messages := e.Messages()
+ c.JSON(e.GetType().GetHttpCode(), &ApiBody{
+ Success: false,
+ Message: e.Error(),
+ Code: code,
+ Causes: messages.Causes(),
+ })
+ } else {
+ logruslog.Global.Error(err, "HTTP %d error (native)",
http.StatusInternalServerError)
+ c.JSON(http.StatusInternalServerError, &ApiBody{
+ Success: false,
+ Code: code,
+ Message: err.Error(),
+ })
+ }
+ c.Writer.Header().Set("Content-Type", "application/json")
+}
+
// ApiOutputError writes a JSON error message to the HTTP response body
func ApiOutputError(c *gin.Context, err error) {
if e, ok := err.(errors.Error); ok {