You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1969,6 +1969,30 @@ class Twitter::API < Grape::API
1969
1969
end
1970
1970
```
1971
1971
1972
+
#### Rescuing exceptions inside namespaces
1973
+
1974
+
You could put `rescue_from` clauses inside a namespace and they will take precedence over ones
1975
+
defined in the root scope:
1976
+
1977
+
```ruby
1978
+
classTwitter::API < Grape::API
1979
+
rescue_from ArgumentErrordo |e|
1980
+
error!("outer")
1981
+
end
1982
+
1983
+
namespace :statusesdo
1984
+
rescue_from ArgumentErrordo |e|
1985
+
error!("inner")
1986
+
end
1987
+
get do
1988
+
raiseArgumentError.new
1989
+
end
1990
+
end
1991
+
end
1992
+
```
1993
+
1994
+
Here `'inner'` will be result of handling occured `ArgumentError`.
1995
+
1972
1996
#### Unrescuable Exceptions
1973
1997
1974
1998
`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