(c *gin.Context, err error, status ...int)
| 111 | } |
| 112 | |
| 113 | func 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 | } |
no test coverage detected