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

Add exception for 429 Too Many Requests errors #2

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

dentarg
Copy link

@dentarg dentarg commented Mar 1, 2024

From campaignmonitor#67

When rate limits are hit a generic CreateSend::ClientError is raised with no explanatory details, which makes implementing a backoff / retry mechanism difficult. If the same request is made manually, we may see a response like:

{
  "Code" => 429,
  "Message" => "Subscriber was added too many times too quickly, try again later."
}

Which allow us to differentiate between rate limiting errors and other client errors. This adds a new CreateSend::TooManyRequests exception to be raised when the API responds with such a 429 so we can do so in code.

CreateSend::TooManyRequests inherits from ClientError, so any current code that rescues ClientError should be unaffected.

When rate limits are hit a generic `CreateSend::ClientError` is raised
with no explanatory details, which makes implementing a backoff / retry
mechanism difficult. If the same request is made manually, we may see a
response like:

```
{
  "Code" => 429,
  "Message" => "Subscriber was added too many times too quickly, try again later."
}
```

Which allow us to differentiate between rate limiting errors and other
client errors. This adds a new `CreateSend::TooManyRequests` exception
to be raised when the API responds with such a 429 so we can do so in
code.

`CreateSend::TooManyRequests` inherits from `ClientError`, so any
current code that rescues `ClientError` should be unaffected.
@dentarg dentarg merged commit b8d87c0 into main Mar 1, 2024
10 checks passed
@dentarg dentarg deleted the add-too-many-requests-exception branch March 1, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants