Skip to content

Commit

Permalink
Add notes about rescue_from to README
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmorrison committed Oct 4, 2024
1 parent fb085cb commit a4ba369
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ TODO: Give more examples of handlers

Use `before_action`, `around_action`, and other callbacks you're used to, as we build on [AbstractController::Callbacks](https://api.rubyonrails.org/classes/AbstractController/Callbacks.html).

### rescue_from

Use `rescue_from` just like you would in a controller:

```ruby
class HaberdasherServiceHandler < Twirp::Rails::Handler
rescue_from "ArgumentError" do |error|
Twirp::Error.invalid_argument(error.message)
end

rescue_from "Pundit::NotAuthorizedError", :not_authorized

...
end
```

### DRY Service Hooks

Apply [Service Hooks](https://github.com/twitchtv/twirp-ruby/wiki/Service-Hooks) one time across multiple services.
Expand Down

0 comments on commit a4ba369

Please sign in to comment.