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 {
|
if success {
|
||||||
LogInfo(r, &rsp)
|
LogInfo(r, &rsp)
|
||||||
} else {
|
} else {
|
||||||
LogError(r, &rsp, errors.Base(consoleText))
|
LogError(r, &rsp, errors.Prefix(consoleText, rsp.Error))
|
||||||
}
|
}
|
||||||
|
|
||||||
// redirect
|
// redirect
|
||||||
|
@ -105,9 +105,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, rsp.RedirectURL, rsp.Status)
|
http.Redirect(w, r, rsp.RedirectURL, rsp.Status)
|
||||||
return
|
return
|
||||||
} else if rsp.RedirectURL != "" {
|
} else if rsp.RedirectURL != "" {
|
||||||
LogError(r, &rsp, errors.Base("status code "+strconv.Itoa(rsp.Status)+
|
LogError(r, &rsp, errors.Base(
|
||||||
" does not indicate a redirect, but RedirectURL is non-empty '"+
|
"status code %d does not indicate a redirect, but RedirectURL is non-empty '%s'",
|
||||||
rsp.RedirectURL+"'"))
|
rsp.Status, rsp.RedirectURL,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
var errorString *string
|
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))
|
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.WriteHeader(rsp.Status)
|
||||||
w.Write(jsonResponse)
|
w.Write(jsonResponse)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package errors
|
package errors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
base "errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
@ -100,8 +99,8 @@ func FullTrace(err error) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base returns a simple error with no stack trace attached
|
// Base returns a simple error with no stack trace attached
|
||||||
func Base(text string) error {
|
func Base(format string, a ...interface{}) error {
|
||||||
return base.New(text)
|
return fmt.Errorf(format, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasTrace checks if error has a trace attached
|
// HasTrace checks if error has a trace attached
|
||||||
|
|
Loading…
Reference in a new issue