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
{{ message }}
Repository navigation
Consider having the renderer decide on success/error with status code. #61
class ApiController < ApplicationController
include ExceptionHandler
end
#controllers/api/v1/concerns/ExceptionHandler.rb
module ExceptionHandler
# provides the more graceful `included` method
extend ActiveSupport::Concern
included do
rescue_from Exception do |exception|
case exception
when ActiveRecord::RecordNotFound
render jsonapi_errors: {message: exception.message}, status: :not_found
when ActiveRecord::RecordInvalid
render jsonapi_errors: {message: exception.message}, status: :unprocessable_entity
# else
# figure out how to render_500
end
end
end
end
Activity
nuheluxulu commentedon Jun 7, 2019
Thanks for this comment.
Solved it as follows:
#controllers/api/v1/api_controller.rb
#controllers/api/v1/concerns/ExceptionHandler.rb