Browse Source

More stable error reporting

development
Godwin 9 years ago
parent
commit
2ee8849153
  1. 79
      app/controllers/application_controller.rb

79
app/controllers/application_controller.rb

@ -115,15 +115,22 @@ class ApplicationController < LinguaFrancaApplicationController
else else
report += " in <code>#{params[:url]}:#{params[:lineNumber]}</code>" report += " in <code>#{params[:url]}:#{params[:lineNumber]}</code>"
end end
UserMailer.error_report(
"A JavaScript error has occurred", suppress(Exception) do
report, # log the error
params[:message], logger.info exception.to_s
nil, logger.info exception.backtrace.join("\n")
request,
params, UserMailer.error_report(
current_user, "A JavaScript error has occurred",
).deliver_now if Rails.env.preview? || Rails.env.production? report,
params[:message],
nil,
request,
params,
current_user,
).deliver_now if Rails.env.preview? || Rails.env.production?
end
render json: {} render json: {}
end end
@ -149,26 +156,28 @@ class ApplicationController < LinguaFrancaApplicationController
end end
rescue_from StandardError do |exception| rescue_from StandardError do |exception|
# send and email if this is production # log the error
UserMailer.error_report(
"An error has occurred in #{Rails.env}",
nil,
exception.to_s,
exception,
request,
params,
current_user,
).deliver_now if Rails.env.preview? || Rails.env.production?
# log the error
logger.info exception.to_s logger.info exception.to_s
logger.info exception.backtrace.join("\n") logger.info exception.backtrace.join("\n")
# show the error page # send and email if this is production
error_500 exception suppress(Exception) do
UserMailer.error_report(
"An error has occurred in #{Rails.env}",
nil,
exception.to_s,
exception,
request,
params,
current_user,
).deliver_now if Rails.env.preview? || Rails.env.production?
end
# raise the error if we are in development so that we can debug it # raise the error if we are in development so that we can debug it
raise exception if Rails.env.development? raise exception if Rails.env.development?
# show the error page
error_500 exception
end end
def generate_confirmation(user, url, expiry = nil) def generate_confirmation(user, url, expiry = nil)
@ -207,7 +216,7 @@ class ApplicationController < LinguaFrancaApplicationController
user.save! user.save!
end end
# genereate the confirmation, send the email and show the 403 # generate the confirmation, send the email and show the 403
referrer = request.referer.gsub(/^.*?\/\/.*?\//, '/') referrer = request.referer.gsub(/^.*?\/\/.*?\//, '/')
generate_confirmation(params[:email], referrer) generate_confirmation(params[:email], referrer)
template = 'login_confirmation_sent' template = 'login_confirmation_sent'
@ -300,15 +309,17 @@ class ApplicationController < LinguaFrancaApplicationController
def i18n_exception(str, exception, locale, key) def i18n_exception(str, exception, locale, key)
# send and email if this is production # send and email if this is production
UserMailer.error_report( suppress(Exception) do
"A missing translation found in #{Rails.env}", UserMailer.error_report(
"<p>A translation for <code>#{key}</code> in <code>#{locale.to_s}</code> was found. The text that was rendered to the user was:</p><blockquote>#{str || 'nil'}</blockquote>", "A missing translation found in #{Rails.env}",
exception.to_s, "<p>A translation for <code>#{key}</code> in <code>#{locale.to_s}</code> was found. The text that was rendered to the user was:</p><blockquote>#{str || 'nil'}</blockquote>",
exception, exception.to_s,
request, exception,
params, request,
current_user, params,
).deliver_now if Rails.env.preview? || Rails.env.production? current_user,
logger.info "Missing translation found for: #{key}" ).deliver_now if Rails.env.preview? || Rails.env.production?
logger.info "Missing translation found for: #{key}"
end
end end
end end

Loading…
Cancel
Save