Skip to content

Instantly share code, notes, and snippets.

@ilake
Created January 2, 2012 06:39
Show Gist options
  • Save ilake/1549611 to your computer and use it in GitHub Desktop.
Save ilake/1549611 to your computer and use it in GitHub Desktop.
ActionController::Metal and Airbrake
class ApiController < ActionController::Metal
include AbstractController::Logger
include Rails.application.routes.url_helpers
include ActionController::Rendering
include ActionController::Renderers::All
include ActionController::MimeResponds
include AbstractController::Callbacks
include Airbrake::Rails::ControllerMethods
around_filter :rescue_error
protected
def rescue_error
begin
yield
rescue ActiveRecord::RecordNotFound => e
render :json => { :message => e.message }.to_json, :status => 404
rescue ActiveRecord::RecordInvalid => e
render :json => { :message => e.message }.to_json, :status => 400
rescue => e
notify_airbrake(e)
render :json => { :message => "Internal Error: #{e}" }.to_json, :status => 500
end
end
end
@maletor
Copy link

maletor commented Feb 28, 2013

Newer versions of Airbrake require

require 'airbrake/rails/controller_methods'

@earnold
Copy link

earnold commented Sep 13, 2013

Thank you for this! 👍

@lucaspiller
Copy link

If anyone comes across this, you just need to upgrade to Airbrake 3.1.17 to fix this error :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment