diff --git a/api/server.go b/api/server.go index 7080292..28b7b2d 100644 --- a/api/server.go +++ b/api/server.go @@ -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) } diff --git a/errors/errors.go b/errors/errors.go index 0d1f38d..1b2c12e 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -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