37c62ac0a3
This occurs mostly when Safari attempts to perform a POST request again (without sending any of the cookies). In that case, our custom `422.html` page is more helpful to the user (because it has a link to the previous page) than a "No cookies" blank text.
30 lines
900 B
Ruby
30 lines
900 B
Ruby
module ApplicationController::ErrorHandling
|
||
extend ActiveSupport::Concern
|
||
|
||
included do
|
||
rescue_from ActionController::InvalidAuthenticityToken do
|
||
# When some browsers (like Safari) re-open a previously closed tab, they attempts
|
||
# to reload the page – even if it is a POST request. But in that case, they don’t
|
||
# sends any of the cookies.
|
||
#
|
||
# In that case, don’t report this error.
|
||
if request.cookies.count > 0
|
||
log_invalid_authenticity_token_error
|
||
end
|
||
|
||
raise # propagate the exception up, to render the default exception page
|
||
end
|
||
end
|
||
|
||
private
|
||
|
||
def log_invalid_authenticity_token_error
|
||
Sentry.with_scope do |temp_scope|
|
||
tags = {
|
||
action: "#{self.class.name}#{action_name}"
|
||
}
|
||
temp_scope.set_tags(tags)
|
||
Sentry.capture_message("ActionController::InvalidAuthenticityToken")
|
||
end
|
||
end
|
||
end
|