Skip to content

Commit

Permalink
add changes of fix portals erros notifications in master (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirineMhedhbi authored Dec 5, 2023
1 parent 1f05f38 commit a2888c9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
12 changes: 12 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
helper_method :bp_config_json, :current_license, :using_captcha?
rescue_from ActiveRecord::RecordNotFound, with: :not_found_record
rescue_from StandardError, with: :internal_server_error

# Pull configuration parameters for REST connection.
REST_URI = $REST_URL
API_KEY = $API_KEY
Expand Down Expand Up @@ -764,4 +766,14 @@ def not_found_record(exception)
@error_message = exception.message
render 'errors/not_found', status: 404
end

def internal_server_error(exception)
current_user = session[:user] if defined?(session)
request_ip = request.remote_ip if defined?(request)
current_url = request.original_url if defined?(request)

Notifier.error(exception, current_user, request_ip, current_url).deliver_now

render 'errors/internal_server_error', status: 500
end
end
31 changes: 9 additions & 22 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
class Notifier < ApplicationMailer

def lost_password(user, password)
# Email header info MUST be added here
recipients user.email
from "#{$SUPPORT_EMAIL}"
subject "[#{$ORG_SITE}] Password Reset"

# Email body substitutions go here
body :user => user, :password => password
end

def error(error)
recipients $ERROR_EMAIL
from "#{$ADMIN_EMAIL}"
subject "Exception Mailer"
body :exception_message => error.message, :trace => error.backtrace
end

def endlessloop(node)
recipients $ERROR_EMAIL
from "#{$ADMIN_EMAIL}"
subject "Exception Mailer"
body :node => node.inspect
def error(error, current_user = nil, request_ip = nil, current_url = nil)
@error_message = error.message
@backtrace = error.backtrace
@current_user = current_user
@request_ip = request_ip
@current_url = current_url

mail(to: "#{$SUPPORT_EMAIL}", from: "#{$SUPPORT_EMAIL}",
subject: "[#{$SITE}] Exception Mailer: #{@error_message}")
end

def feedback(name, email, comment, location, tags)
Expand Down
6 changes: 0 additions & 6 deletions app/views/notifier/error.html.erb

This file was deleted.

31 changes: 31 additions & 0 deletions app/views/notifier/error.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
!!!
%html
%head
%meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%meta{content: "no-cache", name: "turbo-cache-control"}/
%body
%strong Error message:
%p
#{@error_message}
- if @current_user
%p
%strong Current User:
%ul
%li User Name:
= @current_user[:username]
%ul
%li Email:
= @current_user[:email]
- else
%p
%strong Request IP:
= @request_ip
- if @current_url
%p
%strong Current URL:
= @current_url
%p
%br/
%strong Details:
- backtrace = @backtrace.join("\n")
= simple_format(backtrace)

0 comments on commit a2888c9

Please sign in to comment.