How to handle errors / exceptions when calling an external API in Ruby on Rails?

1 answer

Usually I start with one exception to catch them all and move on from there. If there is a specific error that often occurs or needs to be handled differently than another, just add another rescue block above your bottom so that the exception gets there. You do it right :)

Avoid rescue Exception whenever possible, a simple rescue should do the trick.

To clarify, you can get any number of salvations, as well as provide:

 begin do_something rescue CS::BadRequest => e logger.error "..." rescue CS::TimeoutError => e do_something_that_retries rescue => e logger.error "..." ensure send_email_to_admin end 
+7
source

Source: https://habr.com/ru/post/918117/


All Articles