Skip to content

Commit

Permalink
Merge pull request #54 from AlexThurston/fix-error
Browse files Browse the repository at this point in the history
Parse ClickUp error fields
  • Loading branch information
w-haibara authored Mar 29, 2024
2 parents 253e1c3 + 488f4e4 commit 937912e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions clickup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 937912e

Please sign in to comment.