feat(subsonic): log error responses
This commit is contained in:
@@ -54,6 +54,13 @@ func (ew *errWriter) write(buf []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeResp(w http.ResponseWriter, r *http.Request, resp *spec.Response) error {
|
func writeResp(w http.ResponseWriter, r *http.Request, resp *spec.Response) error {
|
||||||
|
if resp == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if resp.Error != nil {
|
||||||
|
log.Printf("subsonic error code %d: %s", resp.Error.Code, resp.Error.Message)
|
||||||
|
}
|
||||||
|
|
||||||
res := metaResponse{Response: resp}
|
res := metaResponse{Response: resp}
|
||||||
params := r.Context().Value(CtxParams).(params.Params)
|
params := r.Context().Value(CtxParams).(params.Params)
|
||||||
ew := &errWriter{w: w}
|
ew := &errWriter{w: w}
|
||||||
@@ -95,25 +102,16 @@ type (
|
|||||||
|
|
||||||
func (c *Controller) H(h handlerSubsonic) http.Handler {
|
func (c *Controller) H(h handlerSubsonic) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
response := h(r)
|
if err := writeResp(w, r, h(r)); err != nil {
|
||||||
if response == nil {
|
log.Printf("error writing subsonic response: %v\n", err)
|
||||||
log.Println("error: non raw subsonic handler returned a nil response")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := writeResp(w, r, response); err != nil {
|
|
||||||
log.Printf("error writing subsonic response (normal handler): %v\n", err)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) HR(h handlerSubsonicRaw) http.Handler {
|
func (c *Controller) HR(h handlerSubsonicRaw) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
response := h(w, r)
|
if err := writeResp(w, r, h(w, r)); err != nil {
|
||||||
if response == nil {
|
log.Printf("error writing raw subsonic response: %v\n", err)
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := writeResp(w, r, response); err != nil {
|
|
||||||
log.Printf("error writing subsonic response (raw handler): %v\n", err)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user