Skip to content

Commit

Permalink
Clarify that rescue_from must return a Rack::Response, re-raise or ca…
Browse files Browse the repository at this point in the history
…ll error./script/quick-start Closes #1151. [ci-skip]
  • Loading branch information
dblock committed Sep 14, 2015
1 parent 3af75a6 commit d3841f1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1529,8 +1529,7 @@ class Twitter::API < Grape::API
end
```

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

```ruby
class Twitter::API < Grape::API
Expand All @@ -1551,9 +1550,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 specific exceptions with a code block and handle the Rack response at the lowest level.

```ruby
class Twitter::API < Grape::API
Expand Down Expand Up @@ -1612,6 +1609,8 @@ rescue_from RuntimeError, rescue_subclasses: false do |e|
end
```

The `rescue_from` block must return a `Rack::Response` object, call `error!` or re-raise an exception.

#### Unrescuable Exceptions

`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.
Expand Down

0 comments on commit d3841f1

Please sign in to comment.