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
+5-16Lines changed: 5 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,25 +66,14 @@ Serialization takes place automatically. For more detailed usage information, pl
66
66
67
67
The default behavior of Grape is to rescue all exceptions and to return a 403 status code with the exception's message in the response body.
68
68
69
-
It's possible to disable this behavior and pass exceptions further up the stack. This usually means displaying the web server's error page as a result.
69
+
It's possible to trap all exceptions by setting `rescue_all_errors true`. This prevents displaying the web server's error page as a result. You may also change the error format to JSON by using `error_format :json` and set the default error status to 200 with `default_error_status 200`.
70
70
71
71
class Twitter::API < Grape::API
72
-
use Grape::Middleware::Error, :rescue => false
73
-
...
74
-
end
75
-
76
-
It's also common to change the error format to JSON.
72
+
rescue_all_errors false
73
+
error_format :json
74
+
default_error_status 200
77
75
78
-
class Twitter::API < Grape::API
79
-
use Grape::Middleware::Error, :format => :json
80
-
...
81
-
end
82
-
83
-
Finally, you can specify your own error formatter. The following example returns a custom error message in the JSON format.
0 commit comments