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
Grape is a REST-like API micro-framework for Ruby. It is built to complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily provide APIs. It has built-in support for common conventions such as multiple formats, subdomain/prefix restriction, and versioning.
4
5
@@ -74,15 +75,12 @@ You can also return JSON formatted objects explicitly by raising error! and pass
74
75
75
76
## Exception Handling
76
77
77
-
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:
78
81
79
82
class Twitter::API < Grape::API
80
-
rescue_all_errors true
81
-
rescue_with_backtrace true
82
-
error_format :json
83
-
default_error_status 200
84
-
85
-
# api methods
83
+
rescue_from ArgumentError, NotImplementedError # :all for all errors
0 commit comments