Created
April 5, 2016 16:31
-
-
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
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
[...] | |
if Rails.env == "staging" | |
require "#{Rails.root}/lib/staging_exception_handler.rb" | |
config.middleware.use StagingExceptionHandler | |
end | |
[...] |
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 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