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

Twirp::Exception to be raised if needed #40

Merged
merged 2 commits into from
Aug 1, 2019
Merged

Conversation

marioizquierdo
Copy link
Collaborator

@marioizquierdo marioizquierdo commented Jul 28, 2019

Fixes #36

Allow to convert a Twirp::Error into a Twirp::Exception, that is an actual exception extended from StandardError. This enables the possibility of raising exceptions from client errors like this:

begin
  resp = client.do_stuff(foo: "bar")
  raise resp.error.to_exception if resp.error
  # ... do stuff with resp.data

rescue Twirp::Exception => e
  case e.code
  when :not_found
    # render not found page
  when :invalid_argument, :permission_denied, :internal
    # etc ...
  end
end

@marioizquierdo marioizquierdo merged commit 64e3dba into master Aug 1, 2019
@marioizquierdo marioizquierdo deleted the twerr_to_exception branch August 1, 2019 18:32
@marioizquierdo
Copy link
Collaborator Author

marioizquierdo commented Aug 1, 2019

Reverted on PR #43, we will not implement exceptions, as per discussed in issue #36

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.

Making Twirp::Error a descendant of StandardError
1 participant