Skip to content

Instantly share code, notes, and snippets.

@nauman
Created November 29, 2012 06:34
Show Gist options
  • Save nauman/4167182 to your computer and use it in GitHub Desktop.
Save nauman/4167182 to your computer and use it in GitHub Desktop.
catch all exceptions
#catch all exceptions
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: :render_500
rescue_from ActionController::RoutingError, with: :render_404
rescue_from ActionController::UnknownController, with: :render_404
rescue_from ActionController::UnknownAction, with: :render_404
rescue_from ActiveRecord::RecordNotFound, with: :render_404
end
private
#generate json messages:
def render_404(exception)
render :json => exception.message
end
def render_500(exception)
render :json => exception.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment