From db31722cfcdbbc01c78b83c45166bc95848c8501 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 22 Jun 2020 20:41:45 -0700 Subject: [PATCH] Don't cause a double stacktrace on certain errors --- api/api.go | 12 +++++++++++- server/install.go | 14 ++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/api/api.go b/api/api.go index a3bb98f..8f9783e 100644 --- a/api/api.go +++ b/api/api.go @@ -130,6 +130,12 @@ func (r *PanelRequest) HttpResponseCode() int { return r.Response.StatusCode } +func IsRequestError(err error) bool { + _, ok := err.(*RequestError) + + return ok +} + type RequestError struct { Code string `json:"code"` Status string `json:"status"` @@ -137,10 +143,14 @@ type RequestError struct { } // Returns the error response in a string form that can be more easily consumed. -func (re *RequestError) String() string { +func (re *RequestError) Error() string { return fmt.Sprintf("%s: %s (HTTP/%s)", re.Code, re.Detail, re.Status) } +func (re *RequestError) String() string { + return re.Error() +} + type RequestErrorBag struct { Errors []RequestError `json:"errors"` } diff --git a/server/install.go b/server/install.go index efa6c92..b89ffae 100644 --- a/server/install.go +++ b/server/install.go @@ -27,10 +27,16 @@ func (s *Server) Install() error { s.Log().Debug("notifying panel of server install state") if serr := s.SyncInstallState(err == nil); serr != nil { - s.Log().WithFields(log.Fields{ - "was_successful": err == nil, - "error": serr, - }).Warn("failed to notify panel of server install state") + l := s.Log().WithField("was_successful", err == nil) + + // If the request was successful but there was an error with this request, attach the + // error to this log entry. Otherwise ignore it in this log since whatever is calling + // this function should handle the error and will end up logging the same one. + if err == nil { + l.WithField("error", serr) + } + + l.Warn("failed to notify panel of server install state") } return err