MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ToHTTP

Function ToHTTP

pkg/errors/http.go:92–100  ·  view source on GitHub ↗

ToHTTP writes the error to the HTTP response.

(in error, w http.ResponseWriter)

Source from the content-addressed store, hash-verified

90
91// ToHTTP writes the error to the HTTP response.
92func 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.
103func FromHTTP(resp *http.Response) error {

Callers 1

TestHTTPFunction · 0.92

Calls 6

FromFunction · 0.85
ToHTTPStatusCodeFunction · 0.85
HeaderMethod · 0.80
NewEncoderMethod · 0.80
SetMethod · 0.65
EncodeMethod · 0.65

Tested by 1

TestHTTPFunction · 0.74