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.markdown
+4-7Lines changed: 4 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,15 +75,12 @@ You can also return JSON formatted objects explicitly by raising error! and pass
75
75
76
76
## Exception Handling
77
77
78
-
By default Grape does not catch all unexpected exceptions. This means that the web server will handle the error and render the default error page as a result. It is possible to trap all exceptions by setting `rescue_all_errors true` instead. You may change the error format to JSON by using `error_format :json` and set the default error status to 200 with `default_error_status 200`. You may also include the complete backtrace of the exception with `rescue_with_backtrace true` either as text (for the :txt format) or as a :backtrace field in the json (for the :json format).
78
+
Grape can be told to rescue certain (or all) exceptions in your
79
+
application and instead display them in text or json form. To do this,
80
+
you simply use the `rescue_from` method inside your API declaration:
79
81
80
82
class Twitter::API < Grape::API
81
-
rescue_all_errors true
82
-
rescue_with_backtrace true
83
-
error_format :json
84
-
default_error_status 200
85
-
86
-
# api methods
83
+
rescue_from ArgumentError, NotImplementedError # :all for all errors
0 commit comments