Module: JSONAPI::Errors
- Defined in:
- lib/jsonapi/errors.rb
Overview
Helpers to handle some error responses
Most of the exceptions are handled in Rails by [ActionDispatch] middleware See: api.rubyonrails.org/classes/ActionDispatch/ExceptionWrapper.html
Class Method Summary collapse
-
.included(base) ⇒ Module
Callback will register the error handlers.
Class Method Details
.included(base) ⇒ Module
Callback will register the error handlers
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jsonapi/errors.rb', line 12 def self.included(base) base.class_eval do rescue_from( StandardError, with: :render_jsonapi_internal_server_error ) unless defined?(::Rails) && ::Rails.env.test? rescue_from( ActiveRecord::RecordNotFound, with: :render_jsonapi_not_found ) if defined?(ActiveRecord::RecordNotFound) rescue_from( ActionController::ParameterMissing, with: :render_jsonapi_unprocessable_entity ) if defined?(ActionController::ParameterMissing) end end |