dont double-log 500s, allow errors.Base() to take args
This commit is contained in:
parent
52d087e920
commit
874481205f
2 changed files with 7 additions and 11 deletions
|
@ -97,7 +97,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
if success {
|
||||
LogInfo(r, &rsp)
|
||||
} else {
|
||||
LogError(r, &rsp, errors.Base(consoleText))
|
||||
LogError(r, &rsp, errors.Prefix(consoleText, rsp.Error))
|
||||
}
|
||||
|
||||
// redirect
|
||||
|
@ -105,9 +105,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
http.Redirect(w, r, rsp.RedirectURL, rsp.Status)
|
||||
return
|
||||
} else if rsp.RedirectURL != "" {
|
||||
LogError(r, &rsp, errors.Base("status code "+strconv.Itoa(rsp.Status)+
|
||||
" does not indicate a redirect, but RedirectURL is non-empty '"+
|
||||
rsp.RedirectURL+"'"))
|
||||
LogError(r, &rsp, errors.Base(
|
||||
"status code %d does not indicate a redirect, but RedirectURL is non-empty '%s'",
|
||||
rsp.Status, rsp.RedirectURL,
|
||||
))
|
||||
}
|
||||
|
||||
var errorString *string
|
||||
|
@ -142,10 +143,6 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
LogError(r, &rsp, errors.Prefix("Error encoding JSON response: ", err))
|
||||
}
|
||||
|
||||
if rsp.Status >= http.StatusInternalServerError {
|
||||
LogError(r, &rsp, errors.Prefix(r.Method+" "+r.URL.Path+"\n", rsp.Error))
|
||||
}
|
||||
|
||||
w.WriteHeader(rsp.Status)
|
||||
w.Write(jsonResponse)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package errors
|
||||
|
||||
import (
|
||||
base "errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
|
@ -100,8 +99,8 @@ func FullTrace(err error) string {
|
|||
}
|
||||
|
||||
// Base returns a simple error with no stack trace attached
|
||||
func Base(text string) error {
|
||||
return base.New(text)
|
||||
func Base(format string, a ...interface{}) error {
|
||||
return fmt.Errorf(format, a...)
|
||||
}
|
||||
|
||||
// HasTrace checks if error has a trace attached
|
||||
|
|
Loading…
Reference in a new issue