MCPcopy
hub / github.com/LyricTian/gin-admin / ResError

Function ResError

pkg/util/gin.go:113–136  ·  view source on GitHub ↗
(c *gin.Context, err error, status ...int)

Source from the content-addressed store, hash-verified

111}
112
113func ResError(c *gin.Context, err error, status ...int) {
114 var ierr *errors.Error
115 if e, ok := errors.As(err); ok {
116 ierr = e
117 } else {
118 ierr = errors.FromError(errors.InternalServerError("", err.Error()))
119 }
120
121 code := int(ierr.Code)
122 if len(status) > 0 {
123 code = status[0]
124 }
125
126 if code >= 500 {
127 ctx := c.Request.Context()
128 ctx = logging.NewTag(ctx, logging.TagKeySystem)
129 ctx = logging.NewStack(ctx, fmt.Sprintf("%+v", err))
130 logging.Context(ctx).Error("Internal server error", zap.Error(err))
131 ierr.Detail = http.StatusText(http.StatusInternalServerError)
132 }
133
134 ierr.Code = int32(code)
135 ResJSON(c, code, ResponseResult{Error: ierr})
136}

Callers 15

RateLimiterWithConfigFunction · 0.92
CasbinWithConfigFunction · 0.92
CopyBodyWithConfigFunction · 0.92
AuthWithConfigFunction · 0.92
RecoveryWithConfigFunction · 0.92
QueryMethod · 0.92
GetMethod · 0.92
CreateMethod · 0.92
UpdateMethod · 0.92
DeleteMethod · 0.92
ResetPasswordMethod · 0.92
GetCaptchaMethod · 0.92

Calls 8

AsFunction · 0.92
FromErrorFunction · 0.92
InternalServerErrorFunction · 0.92
NewTagFunction · 0.92
NewStackFunction · 0.92
ContextFunction · 0.92
ResJSONFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected