Created
January 21, 2009 04:10
-
-
Save jwreagor/49849 to your computer and use it in GitHub Desktop.
Error handling for API serving Rails apps
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
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