Created
September 17, 2018 18:19
-
-
Save phildionne/244dffd492fd795eff3a6d2e1ff55f47 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
# config/application.rb | |
module MyApp | |
class Application < Rails::Application | |
# Handle exceptions with a custom controller | |
config.exceptions_app = lambda do |env| | |
ErrorsController.action(:show).call(env) | |
end | |
end | |
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
<%= javascript_tag do %> | |
document.addEventListener('DOMContentLoaded', function() { | |
Raven.showReportDialog({ | |
eventId: '<%= @sentry_event_id %>' | |
}) | |
}); | |
<% 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 ErrorsController < ApplicationController | |
before_action :fetch_exception | |
layout 'error' | |
def show | |
# Get Sentry event for error feedback | |
@sentry_event_id = Raven.last_event_id | |
render "errors/#{@rescue_response}", status: @status_code | |
rescue ActionView::MissingTemplate | |
render 'errors/internal_server_error', status: 500 | |
end | |
private | |
# Resolves an exception to a HTTP error and status | |
def fetch_exception | |
@exception = request.env['action_dispatch.exception'] | |
@status_code = ActionDispatch::ExceptionWrapper.status_code_for_exception(@exception.class.name) | |
@rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/phildionne/244dffd492fd795eff3a6d2e1ff55f47#file-errors_controller-rb-L8 this is
Nil