Skip to content

Commit e8125c4

Browse files
committed
clarify possibility to combine rescuing all and custom exceptions
1 parent 7e6daeb commit e8125c4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,18 @@ end
18161816

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

1819+
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.
1820+
1821+
```ruby
1822+
class Twitter::API < Grape::API
1823+
rescue_from Grape::Exceptions::ValidationErrors do |e|
1824+
error!(e, 400)
1825+
end
1826+
1827+
rescue_from :all
1828+
end
1829+
```
1830+
18191831
The error format will match the request format. See "Content-Types" below.
18201832

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

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

18681880
```ruby
18691881
class Twitter::API < Grape::API

0 commit comments

Comments
 (0)