Skip to content

Commit e604b11

Browse files
authored
Update readme with error handling example (#768)
* update-readme-with-error-handling-example * add newline for markdown formatting
1 parent 4c92c45 commit e604b11

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,21 @@ is raised and can be rescued and processed. It contains a description
11561156
of the parameter value expectations. Validations can be turned off
11571157
in the configuration file.
11581158

1159+
Here is an example of how to rescue and process a +ParamMissing+ or
1160+
+ParamInvalid+ error from within the ApplicationController.
1161+
1162+
.. code:: ruby
1163+
1164+
class ApplicationController < ActionController::Base
1165+
1166+
# ParamError is superclass of ParamMissing, ParamInvalid
1167+
rescue_from Apipie::ParamError do |e|
1168+
render text: e.message, status: :unprocessable_entity
1169+
end
1170+
1171+
# ...
1172+
end
1173+
11591174
Parameter validation normally happens after before_actions, just before
11601175
your controller method is invoked. If you prefer to control when parameter
11611176
validation occurs, set the configuration parameter ``validate`` to ``:explicitly``.

0 commit comments

Comments
 (0)