1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 15:29:42 +02:00

feat(api): display details in error response (#2228)

This commit is contained in:
Anthony Lapenna 2018-08-30 12:21:53 +02:00 committed by GitHub
parent a5d6ab0410
commit 887c16c580
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,8 @@ type (
Err error
}
errorResponse struct {
Err string `json:"err,omitempty"`
Err string `json:"err,omitempty"`
Details string `json:"details,omitempty"`
}
)
@ -31,7 +32,7 @@ func writeErrorResponse(rw http.ResponseWriter, err *HandlerError) {
log.Printf("http error: %s (err=%s) (code=%d)\n", err.Message, err.Err, err.StatusCode)
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(err.StatusCode)
json.NewEncoder(rw).Encode(&errorResponse{Err: err.Message})
json.NewEncoder(rw).Encode(&errorResponse{Err: err.Message, Details: err.Err.Error()})
}
// WriteError is a convenience function that creates a new HandlerError before calling writeErrorResponse.