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

Twilio delivery method allows Notifier to handle errors #444

Merged
merged 2 commits into from
May 23, 2024

Conversation

bibstha
Copy link
Contributor

@bibstha bibstha commented May 19, 2024

Pull Request

Summary:
This PR allows handling Twilio errors in the Notifier. This is very similar to how other DeliveryMethods do it.
eg in fcm.rb

rescue Noticed::ResponseUnsuccessful => exception
if exception.response.code == "404" && config[:invalid_token]
notification.instance_exec(device_token, &config[:invalid_token])
else
raise
end

Description:
Twilio has very verbose errors (including error codes) that allows API callers to do follow up actions.
eg: Error code 21211 shows that the number is invalid. In this case, we can mark a phone number as invalid to prevent further calls to Twilio.

Testing:
Added a test for the added code.

Screenshots (if applicable):
Also added example in the Twilio documentation

Screenshot 2024-05-19 at 12 15 52 PM

Checklist:

  • Code follows the project's coding standards
  • Tests have been added or updated to cover the changes
  • Documentation has been updated (if applicable)
  • All existing tests pass
  • Conforms to the contributing guidelines

Additional Notes:

@bibstha bibstha force-pushed the twilio-error-handling branch from 597e37a to 52e2af0 Compare May 21, 2024 18:51
@@ -38,6 +38,23 @@ deliver_by :twilio_messaging do |config|
end
```

## Error Handling

Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
Twilio provides a full list of error codes that can be handled as needed. See https://www.twilio.com/docs/api/errors

@excid3
Copy link
Owner

excid3 commented May 23, 2024

I think this makes sense. I don't imagine you'll need to handle anything other than 4xx errors.

@excid3 excid3 merged commit 2ef3c18 into excid3:main May 23, 2024
45 checks passed
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