3 ms·
func (api \*App) HandleOnError(w http.ResponseWriter, err error, status int, context string) bool { if err != nil { api.logging.Error(err, conte
by boredumb 4y ago
func (api \*App) HandleOnError(w http.ResponseWriter,
err error, status int, context string) bool {
if err != nil {
api.logging.Error(err, context)
http.Error(w, err.Error(), http.StatusInternalServerError)
return true
}
return false
}
and then it's used in the handler funcs
if api.HandleOnError(w, err, http.StatusInternalServerError, "Getting stuff for things") {
return
}
Makes the logging verbose and handling always properly taken care of, makes the error handling in handlers verbose enough from the caller but abstract enough to not be a majority of the handlers body.