Skip to content

Instantly share code, notes, and snippets.

@ozydingo
Created April 5, 2016 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozydingo/cc5f0bf7ac21205f4ea180b0245f113a to your computer and use it in GitHub Desktop.
Save ozydingo/cc5f0bf7ac21205f4ea180b0245f113a to your computer and use it in GitHub Desktop.
Intercept routing errors when consider_all_requests_local = true, only show debugging info is user is logger in
[...]
if Rails.env == "staging"
require "#{Rails.root}/lib/staging_exception_handler.rb"
config.middleware.use StagingExceptionHandler
end
[...]
class StagingExceptionHandler
def initialize(app)
@app = app
end
def call(env)
user_id = env["rack.session"]["user_credentials_id"]
code, _, _ = response = @app.call(env)
if user_id.blank? && (400..599).include?(code.to_i)
return ['401', {'Content-Type' => 'text/html'}, ["(#{code}) Danny's not here, Mrs. Torrance."]]
end
return response
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment