ToHTTPStatusCode maps an error to HTTP response codes.
(err error)
| 62 | |
| 63 | // ToHTTPStatusCode maps an error to HTTP response codes. |
| 64 | func ToHTTPStatusCode(err error) int { |
| 65 | for _, err := range Stack(err) { |
| 66 | code := Code(err) |
| 67 | if code == uint32(codes.Unknown) { |
| 68 | continue |
| 69 | } |
| 70 | if status, ok := httpStatusCodes[code]; ok { |
| 71 | return status |
| 72 | } |
| 73 | } |
| 74 | return http.StatusInternalServerError |
| 75 | } |
| 76 | |
| 77 | // FromHTTPStatusCode maps an HTTP response code to an error. |
| 78 | func FromHTTPStatusCode(status int, publicAttributes ...string) *Error { |