Skip to content

Instantly share code, notes, and snippets.

@jwreagor
Created January 21, 2009 04:10
Show Gist options
  • Save jwreagor/49849 to your computer and use it in GitHub Desktop.
Save jwreagor/49849 to your computer and use it in GitHub Desktop.
Error handling for API serving Rails apps
class ApplicationController < ActionController::Base
rescue_from PermissionDenied { |e| http_status_code(:forbidden, e) }
rescue_from AccountExpired { |e| http_status_code(:payment_required, e) }
def http_status_code(status, exception)
respond_to do |format|
self.response.headers["X-Exception"] = @exception = exception
format.html { render :template => "shared/status_#{status.to_s}", :status => status }
format.any { head status }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment