MCPcopy Create free account
hub / github.com/devld/go-drive / apiResultHandler

Function apiResultHandler

server/server.go:124–148  ·  view source on GitHub ↗
(ms i18n.MessageSource)

Source from the content-addressed store, hash-verified

122}
123
124func apiResultHandler(ms i18n.MessageSource) func(*gin.Context) {
125 return func(c *gin.Context) {
126 SetMessageSource(c, ms)
127 c.Next()
128 if len(c.Errors) == 0 {
129 result, exists := GetResult(c)
130 if exists {
131 writeJSON(c, ms, http.StatusOK, result)
132 }
133 return
134 }
135 e := c.Errors[0]
136 code := 500
137 result := types.M{
138 "message": e.Err.Error(),
139 }
140 if re, ok := e.Err.(err.Error); ok {
141 code = re.Code()
142 }
143 if red, ok := e.Err.(err.ErrorWithData); ok {
144 result["data"] = red.Data()
145 }
146 writeJSON(c, ms, code, result)
147 }
148}
149
150func handlePanic(c *gin.Context, err any) {
151 var msg string

Callers 1

InitServerFunction · 0.85

Calls 7

SetMessageSourceFunction · 0.85
GetResultFunction · 0.85
writeJSONFunction · 0.85
NextMethod · 0.80
ErrorMethod · 0.65
CodeMethod · 0.65
DataMethod · 0.65

Tested by

no test coverage detected