ToHTTP writes the error to the HTTP response.
(in error, w http.ResponseWriter)
| 90 | |
| 91 | // ToHTTP writes the error to the HTTP response. |
| 92 | func ToHTTP(in error, w http.ResponseWriter) error { |
| 93 | w.Header().Set("Content-Type", "application/json") |
| 94 | if ttnErr, ok := From(in); ok { |
| 95 | w.WriteHeader(ToHTTPStatusCode(ttnErr)) |
| 96 | return json.NewEncoder(w).Encode(ttnErr) |
| 97 | } |
| 98 | w.WriteHeader(http.StatusInternalServerError) |
| 99 | return json.NewEncoder(w).Encode(in) |
| 100 | } |
| 101 | |
| 102 | // FromHTTP reads an error from the HTTP response. |
| 103 | func FromHTTP(resp *http.Response) error { |