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::Service.error_response(twerr) method #34

Merged
merged 2 commits into from
Apr 16, 2019

Conversation

marioizquierdo
Copy link
Collaborator

@marioizquierdo marioizquierdo commented Apr 14, 2019

Allows to easily make valid error responses from outside Twirp:

twerr = Twirp::Error.internal("Oops")
[status, headers, body] = Twirp::Service.error_response(twerr)

For example, from Rack middleware:

class MyMiddleware
  def initialize(app)
    @app = app       
  end                

  def call(env)      
    // do some stuff and decide to return an early Twirp error
    if not_cool(env)
      twerr = Twirp::Error.invalid_argument("not cool", foo: "bar-meta")
      return Twirp::Service.error_response(twerr)
    end

    @app.call(env)   
  end                
end

@marioizquierdo marioizquierdo merged commit d0cb840 into master Apr 16, 2019
@marioizquierdo marioizquierdo deleted the service_error_response_helper branch April 23, 2021 05:19
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.

1 participant