Browse Source

More stable error reporting

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

25
app/controllers/application_controller.rb

@ -115,6 +115,12 @@ class ApplicationController < LinguaFrancaApplicationController
else
report += " in <code>#{params[:url]}:#{params[:lineNumber]}</code>"
end
suppress(Exception) do
# log the error
logger.info exception.to_s
logger.info exception.backtrace.join("\n")
UserMailer.error_report(
"A JavaScript error has occurred",
report,
@ -124,6 +130,7 @@ class ApplicationController < LinguaFrancaApplicationController
params,
current_user,
).deliver_now if Rails.env.preview? || Rails.env.production?
end
render json: {}
end
@ -149,7 +156,12 @@ class ApplicationController < LinguaFrancaApplicationController
end
rescue_from StandardError do |exception|
# log the error
logger.info exception.to_s
logger.info exception.backtrace.join("\n")
# send and email if this is production
suppress(Exception) do
UserMailer.error_report(
"An error has occurred in #{Rails.env}",
nil,
@ -159,16 +171,13 @@ class ApplicationController < LinguaFrancaApplicationController
params,
current_user,
).deliver_now if Rails.env.preview? || Rails.env.production?
end
# log the error
logger.info exception.to_s
logger.info exception.backtrace.join("\n")
# raise the error if we are in development so that we can debug it
raise exception if Rails.env.development?
# show the error page
error_500 exception
# raise the error if we are in development so that we can debug it
raise exception if Rails.env.development?
end
def generate_confirmation(user, url, expiry = nil)
@ -207,7 +216,7 @@ class ApplicationController < LinguaFrancaApplicationController
user.save!
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(/^.*?\/\/.*?\//, '/')
generate_confirmation(params[:email], referrer)
template = 'login_confirmation_sent'
@ -300,6 +309,7 @@ class ApplicationController < LinguaFrancaApplicationController
def i18n_exception(str, exception, locale, key)
# send and email if this is production
suppress(Exception) do
UserMailer.error_report(
"A missing translation found in #{Rails.env}",
"<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>",
@ -312,3 +322,4 @@ class ApplicationController < LinguaFrancaApplicationController
logger.info "Missing translation found for: #{key}"
end
end
end

Loading…
Cancel
Save