GetHTTPCode retrieves the HTTP code from a stack of causes.
(err error, defaultCode int)
| 43 | |
| 44 | // GetHTTPCode retrieves the HTTP code from a stack of causes. |
| 45 | func GetHTTPCode(err error, defaultCode int) int { |
| 46 | if v, ok := markers.If(err, func(err error) (interface{}, bool) { |
| 47 | if w, ok := err.(*withHTTPCode); ok { |
| 48 | return w.code, true |
| 49 | } |
| 50 | return nil, false |
| 51 | }); ok { |
| 52 | return v.(int) |
| 53 | } |
| 54 | return defaultCode |
| 55 | } |
| 56 | |
| 57 | // it's an error. |
| 58 | func (w *withHTTPCode) Error() string { return w.cause.Error() } |