mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Review feedback.
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
parent
f83155b11e
commit
901e6d1f82
|
@ -843,7 +843,18 @@ func (api *API) respond(w http.ResponseWriter, data interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data interface{}) {
|
func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data interface{}) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
b, err := json.Marshal(&response{
|
||||||
|
Status: statusError,
|
||||||
|
ErrorType: apiErr.typ,
|
||||||
|
Error: apiErr.err.Error(),
|
||||||
|
Data: data,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
level.Error(api.logger).Log("msg", "error marshalling json response", "err", err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var code int
|
var code int
|
||||||
switch apiErr.typ {
|
switch apiErr.typ {
|
||||||
|
@ -860,22 +871,9 @@ func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data inter
|
||||||
default:
|
default:
|
||||||
code = http.StatusInternalServerError
|
code = http.StatusInternalServerError
|
||||||
}
|
}
|
||||||
w.WriteHeader(code)
|
|
||||||
|
|
||||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
w.Header().Set("Content-Type", "application/json")
|
||||||
b, err := json.Marshal(&response{
|
w.WriteHeader(code)
|
||||||
Status: statusError,
|
|
||||||
ErrorType: apiErr.typ,
|
|
||||||
Error: apiErr.err.Error(),
|
|
||||||
Data: data,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
level.Error(api.logger).Log("msg", "error marshalling json response", "err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if n, err := w.Write(b); err != nil {
|
if n, err := w.Write(b); err != nil {
|
||||||
level.Error(api.logger).Log("msg", "error writing response", "n", n, "err", err)
|
level.Error(api.logger).Log("msg", "error writing response", "n", n, "err", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue