Skip to content

Commit d3841f1

Browse files
committed
Clarify that rescue_from must return a Rack::Response, re-raise or call error./script/quick-start Closes #1151. [ci-skip]
1 parent 3af75a6 commit d3841f1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,8 +1529,7 @@ class Twitter::API < Grape::API
15291529
end
15301530
```
15311531

1532-
You can rescue all exceptions with a code block. The `error!` wrapper
1533-
automatically sets the default error code and content-type.
1532+
You can rescue all exceptions with a code block. The `error!` wrapper automatically sets the default error code and content-type.
15341533

15351534
```ruby
15361535
class Twitter::API < Grape::API
@@ -1551,9 +1550,7 @@ class Twitter::API < Grape::API
15511550
end
15521551
```
15531552

1554-
1555-
You can also rescue specific exceptions with a code block and handle the Rack
1556-
response at the lowest level.
1553+
You can also rescue specific exceptions with a code block and handle the Rack response at the lowest level.
15571554

15581555
```ruby
15591556
class Twitter::API < Grape::API
@@ -1612,6 +1609,8 @@ rescue_from RuntimeError, rescue_subclasses: false do |e|
16121609
end
16131610
```
16141611

1612+
The `rescue_from` block must return a `Rack::Response` object, call `error!` or re-raise an exception.
1613+
16151614
#### Unrescuable Exceptions
16161615

16171616
`Grape::Exceptions::InvalidVersionHeader`, which is raised when the version in the request header doesn't match the currently evaluated version for the endpoint, will _never_ be rescued from a `rescue_from` block (even a `rescue_from :all`) This is because Grape relies on Rack to catch that error and try the next versioned-route for cases where there exist identical Grape endpoints with different versions.

0 commit comments

Comments
 (0)