Created
August 4, 2011 07:13
-
-
Save ept/1124644 to your computer and use it in GitHub Desktop.
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 BridgeController < ApplicationController | |
rescue_from YouShallNotPassException, :status => 403, :error_code => 'no_way' do |exception, response| | |
response[:where] = exception.backtrace.first | |
end | |
# Assuming a route like this: | |
# map.connect "/khazad_dum/bridge/cross", :controller => :bridge, :action => :cross, :format => :json | |
# then this will return a HTTP 403 error with the following JSON object as body: | |
# {"error_code": "no_way", "message": "No balrogs past this point please", | |
# "where": "bridge_controller.rb:12:in `cross'"} | |
def cross | |
raise YouShallNotPassException, "No balrogs past this point please" if current_user.is_a?(Balrog) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment