From 488f4e4a8b6029713ac50689a7221c7de7534341 Mon Sep 17 00:00:00 2001 From: Alex Thurston Date: Mon, 5 Feb 2024 08:19:41 -0500 Subject: [PATCH] Parse ClickUp error fields --- clickup/client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/clickup/client.go b/clickup/client.go index b18e1e7..82c05b2 100644 --- a/clickup/client.go +++ b/clickup/client.go @@ -393,6 +393,8 @@ An ErrorResponse reports one or more errors caused by an API request. */ type ErrorResponse struct { Response *http.Response // HTTP response that caused this error + Err string `json:"err"` + ECode string `json:"ECODE"` Message string `json:"message"` // error message Errors []Error `json:"errors"` // more detail on individual errors // Block is only populated on certain types of errors such as code 451. @@ -407,8 +409,7 @@ type ErrorBlock struct { func (r *ErrorResponse) Error() string { return fmt.Sprintf("%v %v: %d %v %+v", - r.Response.Request.Method, sanitizeURL(r.Response.Request.URL), - r.Response.StatusCode, r.Message, r.Errors) + r.Response.Request.Method, sanitizeURL(r.Response.Request.URL), r.Response.StatusCode, r.Err, r.ECode) } // Is returns whether the provided error equals this error. @@ -418,7 +419,7 @@ func (r *ErrorResponse) Is(target error) bool { return false } - if r.Message != v.Message || !compareHttpResponse(r.Response, v.Response) { + if r.Message != v.Message || !compareHttpResponse(r.Response, v.Response) || r.Err != v.Err || r.ECode != v.ECode { return false } @@ -563,12 +564,12 @@ func CheckResponse(r *http.Response) error { return nil } errorResponse := &ErrorResponse{Response: r} - data, err := ioutil.ReadAll(r.Body) + data, err := io.ReadAll(r.Body) if err == nil && data != nil { json.Unmarshal(data, errorResponse) } - r.Body = ioutil.NopCloser(bytes.NewBuffer(data)) + r.Body = io.NopCloser(bytes.NewBuffer(data)) switch { case r.StatusCode == http.StatusTooManyRequests && r.Header.Get(headerRateRemaining) == "0": return &RateLimitError{