Skip to content

Commit

Permalink
Merge pull request ruby-grape#1404 from hedgesky/improving_exception_…
Browse files Browse the repository at this point in the history
…handling_section_in_readme

clarify possibility to combine rescuing all and custom exceptions
  • Loading branch information
dblock committed May 21, 2016
2 parents 7e6daeb + e8125c4 commit dc39328
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,18 @@ end

In this case ```UserDefinedError``` must be inherited from ```StandardError```.

Notice that you could combine these two approaches (rescuing custom errors takes precedence). For example, it's useful for handling all exceptions except Grape validation errors.

```ruby
class Twitter::API < Grape::API
rescue_from Grape::Exceptions::ValidationErrors do |e|
error!(e, 400)
end

rescue_from :all
end
```

The error format will match the request format. See "Content-Types" below.

Custom error formatters for existing and additional types can be defined with a proc.
Expand Down Expand Up @@ -1863,7 +1875,7 @@ class Twitter::API < Grape::API
end
```

You can also rescue specific exceptions with a code block and handle the Rack response at the lowest level.
You can also rescue all exceptions with a code block and handle the Rack response at the lowest level.

```ruby
class Twitter::API < Grape::API
Expand Down

0 comments on commit dc39328

Please sign in to comment.