Send Subsonic formatted response on marshalling errors
This commit is contained in:
@@ -233,7 +233,7 @@ func h501(r chi.Router, paths ...string) {
|
||||
for _, path := range paths {
|
||||
handle := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Cache-Control", "no-cache")
|
||||
w.WriteHeader(501)
|
||||
w.WriteHeader(http.StatusNotImplemented)
|
||||
_, _ = w.Write([]byte("This endpoint is not implemented, but may be in future releases"))
|
||||
}
|
||||
addHandler(r, path, handle)
|
||||
@@ -244,7 +244,7 @@ func h501(r chi.Router, paths ...string) {
|
||||
func h410(r chi.Router, paths ...string) {
|
||||
for _, path := range paths {
|
||||
handle := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(410)
|
||||
w.WriteHeader(http.StatusGone)
|
||||
_, _ = w.Write([]byte("This endpoint will not be implemented"))
|
||||
}
|
||||
addHandler(r, path, handle)
|
||||
@@ -276,7 +276,7 @@ func mapToSubsonicError(err error) subError {
|
||||
func sendError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
subErr := mapToSubsonicError(err)
|
||||
response := newResponse()
|
||||
response.Status = "failed"
|
||||
response.Status = responses.StatusFailed
|
||||
response.Error = &responses.Error{Code: int32(subErr.code), Message: subErr.Error()}
|
||||
|
||||
sendResponse(w, r, response)
|
||||
@@ -305,11 +305,10 @@ func sendResponse(w http.ResponseWriter, r *http.Request, payload *responses.Sub
|
||||
// This should never happen, but if it does, we need to know
|
||||
if err != nil {
|
||||
log.Error(r.Context(), "Error marshalling response", "format", f, err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_, _ = w.Write([]byte("Internal Server Error: " + err.Error()))
|
||||
sendError(w, r, err)
|
||||
return
|
||||
}
|
||||
if payload.Status == "ok" {
|
||||
if payload.Status == responses.StatusOK {
|
||||
if log.IsGreaterOrEqualTo(log.LevelTrace) {
|
||||
log.Debug(r.Context(), "API: Successful response", "endpoint", r.URL.Path, "status", "OK", "body", string(response))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user