Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse ClickUp error fields #54

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines -566 to +567
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

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
Loading