Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Feature: handle rescue_from Module arguments properly#19

Merged
exAspArk merged 1 commit intoexAspArk:masterfrom
sclinede:master
Nov 12, 2019
Merged

Feature: handle rescue_from Module arguments properly#19
exAspArk merged 1 commit intoexAspArk:masterfrom
sclinede:master

Conversation

@sclinede
Copy link
Copy Markdown
Contributor

@sclinede sclinede commented Nov 9, 2019

There is a common pattern for rescue_from and alike methods usage, to
pass as an argument a module which handles similar exceptions
processing. The most useful case (and the reason why I proposed that
change) is to handle different network errors with only on module.

In our project it's called Handle::NetworkErrors, it's a module which
aggregates handling of more then 20 different errors whose meaning is
just "something was wrong with the network" and in 99% of the cases it's
reasonable to handle them in exact similar way.

Unfortunately, without proposed change it's impossible to pass to
graphql-errors rescue_from a module. It has to be a class...
The other implementations of same method in Rails and Sidekiq accepts
Module as well as a Class.

So, my point is that would be great to have rescue_from behavior in a
canonical way (or you may call it, principle of least surprise).

Hope you'll find it useful and thanks for your nice gem.

There is a common pattern for `rescue_from` and alike methods usage, to
pass as an argument a module which handles similar exceptions
processing. The most useful case (and the reason why I proposed that
change) is to handle different network errors with only on class.

In our project it's called Handle::NetworkErrors, it's a module which
aggregates handling of more then 20 different errors whose meaning is
just "something was wrong with the network" and in 99% of the cases it's
reasonable to handle them in exact similar way.

Unfortunately, without proposed change it's impossible to pass to
graphql-errors `rescue_from` a module. It has to be a class...
The other implementations of same method in Rails and Sidekiq accepts
Module as well as a Class.

So, my point is that would be great to have `rescue_from` behavior in a
cannonical way (or you may call it, principle of least surprise).
@sclinede
Copy link
Copy Markdown
Contributor Author

@exAspArk mentioned you here, just in case 🙏

describe '#rescue_from' do
it 'raises an exception if the object which was passed is not a class' do
before do
module NetworkErrors
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

we could potentially define it outside the before block which is being triggered for every test to avoid:

warning: already initialized constant NetworkErrors::ERRORS

@exAspArk
Copy link
Copy Markdown
Owner

exAspArk commented Nov 12, 2019

@sclinede amazing! Released your changes in version 0.4.0.

Спасибо за пул реквест и развернутое описание :)

@exAspArk exAspArk merged commit 48e9815 into exAspArk:master Nov 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants