From 597e37a0b2c221ce9aff1701b870757a2c9e8cae Mon Sep 17 00:00:00 2001 From: Bibek Shrestha Date: Sun, 19 May 2024 12:10:06 -0700 Subject: [PATCH] Add an example how to handle Twilio error --- docs/delivery_methods/twilio_messaging.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/delivery_methods/twilio_messaging.md b/docs/delivery_methods/twilio_messaging.md index 37c1f997..b4308b45 100644 --- a/docs/delivery_methods/twilio_messaging.md +++ b/docs/delivery_methods/twilio_messaging.md @@ -38,6 +38,23 @@ deliver_by :twilio_messaging do |config| end ``` +## Error Handling + +```ruby +deliver_by :twilio_messaging do |config| + config.error_handler = lambda do |twilio_error_response| + error_hash = JSON.parse(twilio_error_response.body) + case error_hash["code"] + when 21211 + # The 'To' number is not a valid phone number. + # Write your error handling code + else + raise "Unhandled Twilio error: #{error_hash}" + end + end +end +``` + ## Options * `json` - *Optional*