FromHTTPStatusCode maps an HTTP response code to an error.
(status int, publicAttributes ...string)
| 76 | |
| 77 | // FromHTTPStatusCode maps an HTTP response code to an error. |
| 78 | func FromHTTPStatusCode(status int, publicAttributes ...string) *Error { |
| 79 | code := uint32(codes.Unknown) |
| 80 | if c, ok := httpErrorCodes[status]; ok { |
| 81 | code = c |
| 82 | } |
| 83 | return build(&Definition{ |
| 84 | namespace: namespace(2), |
| 85 | messageFormat: http.StatusText(status), |
| 86 | publicAttributes: publicAttributes, |
| 87 | code: code, |
| 88 | }, 4) |
| 89 | } |
| 90 | |
| 91 | // ToHTTP writes the error to the HTTP response. |
| 92 | func ToHTTP(in error, w http.ResponseWriter) error { |