Merge pull request #404 from RichardScothern/digest-log
Add logging for generic handler errors.
This commit is contained in:
commit
70e6ad6ef1
1 changed files with 14 additions and 0 deletions
|
@ -365,11 +365,25 @@ func (app *App) dispatcher(dispatch dispatchFunc) http.Handler {
|
||||||
// future refactoring.
|
// future refactoring.
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
app.logError(context, context.Errors)
|
||||||
serveJSON(w, context.Errors)
|
serveJSON(w, context.Errors)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) logError(context context.Context, errors v2.Errors) {
|
||||||
|
for _, e := range errors.Errors {
|
||||||
|
c := ctxu.WithValue(context, "err.code", e.Code)
|
||||||
|
c = ctxu.WithValue(c, "err.message", e.Message)
|
||||||
|
c = ctxu.WithValue(c, "err.detail", e.Detail)
|
||||||
|
c = ctxu.WithLogger(c, ctxu.GetLogger(c,
|
||||||
|
"err.code",
|
||||||
|
"err.message",
|
||||||
|
"err.detail"))
|
||||||
|
ctxu.GetLogger(c).Errorf("An error occured")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// context constructs the context object for the application. This only be
|
// context constructs the context object for the application. This only be
|
||||||
// called once per request.
|
// called once per request.
|
||||||
func (app *App) context(w http.ResponseWriter, r *http.Request) *Context {
|
func (app *App) context(w http.ResponseWriter, r *http.Request) *Context {
|
||||||
|
|
Loading…
Reference in a new issue