From a4ba369236db7384c0456a86aedb6f97da787e4e Mon Sep 17 00:00:00 2001 From: Daniel Morrison Date: Fri, 4 Oct 2024 11:19:02 -0400 Subject: [PATCH] Add notes about rescue_from to README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 6d42ec9..34bfaa2 100644 --- a/README.md +++ b/README.md @@ -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.