ErrToHTTP convert to standard error add ToHTTPCodeLabel to error message, use it if you need to convert to standard HTTP status code, if there is a parameter 'msg', it will replace the original message. Tips: you can call the GetErrorCode function to get the standard HTTP status code.
(msg ...string)
| 59 | // if there is a parameter 'msg', it will replace the original message. |
| 60 | // Tips: you can call the GetErrorCode function to get the standard HTTP status code. |
| 61 | func (e *Error) ErrToHTTP(msg ...string) error { |
| 62 | message := e.msg |
| 63 | if len(msg) > 0 { |
| 64 | message = strings.Join(msg, ", ") |
| 65 | } |
| 66 | |
| 67 | if len(e.details) == 0 { |
| 68 | return fmt.Errorf("code = %d, msg = %s%s", e.code, message, ToHTTPCodeLabel) |
| 69 | } |
| 70 | return fmt.Errorf("code = %d, msg = %s, details = %v%s", e.code, message, strings.Join(e.details, ", "), ToHTTPCodeLabel) |
| 71 | } |
| 72 | |
| 73 | // Code get error code |
| 74 | func (e *Error) Code() int { |