Don't cause a double stacktrace on certain errors

This commit is contained in:
Dane Everitt 2020-06-22 20:41:45 -07:00
parent d91de3d912
commit db31722cfc
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 21 additions and 5 deletions

View File

@ -130,6 +130,12 @@ func (r *PanelRequest) HttpResponseCode() int {
return r.Response.StatusCode return r.Response.StatusCode
} }
func IsRequestError(err error) bool {
_, ok := err.(*RequestError)
return ok
}
type RequestError struct { type RequestError struct {
Code string `json:"code"` Code string `json:"code"`
Status string `json:"status"` 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. // 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) return fmt.Sprintf("%s: %s (HTTP/%s)", re.Code, re.Detail, re.Status)
} }
func (re *RequestError) String() string {
return re.Error()
}
type RequestErrorBag struct { type RequestErrorBag struct {
Errors []RequestError `json:"errors"` Errors []RequestError `json:"errors"`
} }

View File

@ -27,10 +27,16 @@ func (s *Server) Install() error {
s.Log().Debug("notifying panel of server install state") s.Log().Debug("notifying panel of server install state")
if serr := s.SyncInstallState(err == nil); serr != nil { if serr := s.SyncInstallState(err == nil); serr != nil {
s.Log().WithFields(log.Fields{ l := s.Log().WithField("was_successful", err == nil)
"was_successful": err == nil,
"error": serr, // If the request was successful but there was an error with this request, attach the
}).Warn("failed to notify panel of server install state") // 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 return err