Created
March 30, 2016 08:41
-
-
Save jordifierro/481a061fc911536726c4c7c2a7130520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api::V1::Concerns | |
module ErrorHandler | |
extend ActiveSupport::Concern | |
included do | |
rescue_from ActiveRecord::RecordNotFound, with: :not_found | |
end | |
def render_error(message, status) | |
status_code = Rack::Utils::SYMBOL_TO_STATUS_CODE[status] | |
render json: { error: { status: status_code, message: message } }, | |
status: status | |
end | |
def not_found | |
render_error(I18n.t('errors.messages.not_found'), :not_found) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment