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

Allow handlers to use rescue_from in a way familiar to ActionController users #19

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

danielmorrison
Copy link
Member

@danielmorrison danielmorrison commented Oct 4, 2024

ActiveSupport::Rescuable does close to what we need, but rather than calling render or redirect, handlers return an object (which may be a Twirp::Error). We refine ActiveSupport::Rescuable to return the result of the rescue_from block/method.

  • Add docs to README

…er users

ActiveSupport::Rescuable does close to what we need, but rather than calling render or redirect, handlers return an object (which may be a Twirp::Error). We refine ActiveSupport::Rescuable to return the result of the rescue_from block/method.
Comment on lines +10 to +18
visited_exceptions << exception

if (handler = handler_for_rescue(exception, object: object))
handler.call exception
elsif exception
if visited_exceptions.include?(exception.cause)
nil
else
rescue_with_handler(exception.cause, object: object, visited_exceptions: visited_exceptions)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
visited_exceptions << exception
if (handler = handler_for_rescue(exception, object: object))
handler.call exception
elsif exception
if visited_exceptions.include?(exception.cause)
nil
else
rescue_with_handler(exception.cause, object: object, visited_exceptions: visited_exceptions)
if (handler = handler_for_rescue(exception, object: object))
handler.call exception
elsif exception
if visited_exceptions.include?(exception.cause)
nil
else
rescue_with_handler(exception.cause, object: object, visited_exceptions: visited_exceptions << exception)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's better, but the original method was copied out of ActiveSupport so I'm tempted to leave it as close as possible for easier comparison in the future.

@danielmorrison danielmorrison merged commit a84c47a into main Oct 4, 2024
5 checks passed
@danielmorrison danielmorrison deleted the rescue_from branch October 4, 2024 18:04
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