fga-eps-mds/2018.2-IndicaAi

View on GitHub
indicaAi/app/controllers/concerns/exception_handler.rb

Summary

Maintainability
A
0 mins
Test Coverage
# This module provides json responses to exceptions
module ExceptionHandler
  # provides the more graceful `included` method
  extend ActiveSupport::Concern

  included do
    rescue_from ActiveRecord::RecordNotFound do |e|
      json_response({ message: e.message }, :not_found)
    end

    rescue_from ActiveRecord::RecordInvalid do |e|
      json_response({ message: e.message }, :unprocessable_entity)
    end
  end
end