Skip to content

Instantly share code, notes, and snippets.

@jordifierro
Created March 30, 2016 08:41
Show Gist options
  • Save jordifierro/481a061fc911536726c4c7c2a7130520 to your computer and use it in GitHub Desktop.
Save jordifierro/481a061fc911536726c4c7c2a7130520 to your computer and use it in GitHub Desktop.
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