More stable error reporting
This commit is contained in:
		
							parent
							
								
									6781b41e04
								
							
						
					
					
						commit
						2ee8849153
					
				@ -115,6 +115,12 @@ class ApplicationController < LinguaFrancaApplicationController
 | 
				
			|||||||
		else
 | 
							else
 | 
				
			||||||
			report += " in <code>#{params[:url]}:#{params[:lineNumber]}</code>"
 | 
								report += " in <code>#{params[:url]}:#{params[:lineNumber]}</code>"
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							suppress(Exception) do
 | 
				
			||||||
 | 
								# log the error
 | 
				
			||||||
 | 
								logger.info exception.to_s
 | 
				
			||||||
 | 
								logger.info exception.backtrace.join("\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			UserMailer.error_report(
 | 
								UserMailer.error_report(
 | 
				
			||||||
					"A JavaScript error has occurred",
 | 
										"A JavaScript error has occurred",
 | 
				
			||||||
					report,
 | 
										report,
 | 
				
			||||||
@ -124,6 +130,7 @@ class ApplicationController < LinguaFrancaApplicationController
 | 
				
			|||||||
					params,
 | 
										params,
 | 
				
			||||||
					current_user,
 | 
										current_user,
 | 
				
			||||||
				).deliver_now if Rails.env.preview? || Rails.env.production?
 | 
									).deliver_now if Rails.env.preview? || Rails.env.production?
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
		render json: {}
 | 
							render json: {}
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -149,7 +156,12 @@ class ApplicationController < LinguaFrancaApplicationController
 | 
				
			|||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rescue_from StandardError do |exception|
 | 
						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
 | 
							# send and email if this is production
 | 
				
			||||||
 | 
							suppress(Exception) do
 | 
				
			||||||
			UserMailer.error_report(
 | 
								UserMailer.error_report(
 | 
				
			||||||
					"An error has occurred in #{Rails.env}",
 | 
										"An error has occurred in #{Rails.env}",
 | 
				
			||||||
					nil,
 | 
										nil,
 | 
				
			||||||
@ -159,16 +171,13 @@ class ApplicationController < LinguaFrancaApplicationController
 | 
				
			|||||||
					params,
 | 
										params,
 | 
				
			||||||
					current_user,
 | 
										current_user,
 | 
				
			||||||
				).deliver_now if Rails.env.preview? || Rails.env.production?
 | 
									).deliver_now if Rails.env.preview? || Rails.env.production?
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
		# log the error		
 | 
					 | 
				
			||||||
		logger.info exception.to_s
 | 
					 | 
				
			||||||
		logger.info exception.backtrace.join("\n")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		# show the error page
 | 
					 | 
				
			||||||
		error_500 exception
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# 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,6 +309,7 @@ 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
 | 
				
			||||||
 | 
							suppress(Exception) do
 | 
				
			||||||
			UserMailer.error_report(
 | 
								UserMailer.error_report(
 | 
				
			||||||
					"A missing translation found in #{Rails.env}",
 | 
										"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>",
 | 
										"<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>",
 | 
				
			||||||
@ -311,4 +321,5 @@ class ApplicationController < LinguaFrancaApplicationController
 | 
				
			|||||||
				).deliver_now if Rails.env.preview? || Rails.env.production?
 | 
									).deliver_now if Rails.env.preview? || Rails.env.production?
 | 
				
			||||||
			logger.info "Missing translation found for: #{key}"
 | 
								logger.info "Missing translation found for: #{key}"
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user