I'm using a library to handle error responses across five different API 
apps. To stop all processing, this library raises an error that is later 
rescued with `rescue_from`.

Since DRY is important to me, I also want to avoid repeating the 
`rescue_from` call and its handler block in all five applications. 
Furthermore, if I someday decide to change the handler, I would need to 
update all five applications.

Solution I've found is to extend my error class with a `to_proc` method 
that generates a proc handling the response in the controller (in this 
case: `render json: exception.reply`). I've patched rails to this end: 
`rescue_from` can now be called without a block handler, in which case the 
block handler will be the proc of the exception.

Full diff patch with tests is here: 
https://gist.github.com/joshleaves/10de348b0e8b28863213

I'm waiting for feedback before submitting the PR. Thanks =)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to