Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Exception notifier #416

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ gem 'rails-jquery-tokeninput'
gem 'jquery-datatables-rails', '~> 3.4.0'
# Use signature pad
gem 'signature-pad-rails'
# exception notifications
gem 'exception_notification'

# pagination
gem 'will_paginate'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="https://codeclimate.com/github/umts/golf-cart-rentals"><img src="https://codeclimate.com/github/umts/golf-cart-rentals/badges/gpa.svg" /></a>
<a href="https://codeclimate.com/github/umts/golf-cart-rentals/coverage"><img src="https://codeclimate.com/github/umts/golf-cart-rentals/badges/coverage.svg" /></a>

Gold Cart Rentals is a piece of web-based rental control software.
Golf Cart Rentals is a piece of web-based rental control software.

For instructions on setting up golf-cart-rentals, see the [Wiki](https://github.com/umts/golf-cart-rentals/wiki/Getting-Started-with-golf-cart-rentals!)

Expand Down
Empty file removed app/assets/images/.keep
Empty file.
22 changes: 0 additions & 22 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ApplicationController < ActionController::Base
# Set auto papertrail
before_action :set_paper_trail_whodunnit

rescue_from RuntimeError, Exception, with: :render_500 unless Rails.env.development?
rescue_from ActiveRecord::RecordNotFound, with: :render_404 unless Rails.env.development?
rescue_from MissingUserError, with: :render_401

Expand All @@ -30,20 +29,6 @@ def render_404
end
end

def render_500(error)
# make sure to log the error
logger.error error.message
logger.error error.backtrace.join("\n")

# send email to IT
send_error_email(error)

respond_to do |format|
format.html { render template: 'errors/500.html.erb', status: 500 }
format.all { render body: nil, status: 500 }
end
end

def render_401
render template: 'errors/401.html.erb', layout: false, status: 401
end
Expand Down Expand Up @@ -88,13 +73,6 @@ def has_permission?

private

def send_error_email(error)
user = @current_user
serializable_error = { class: error.class.to_s, message: error.message, trace: error.backtrace }
ErrorMailer.error_email('[email protected]', request.fullpath, user,
serializable_error).deliver_later
end

def check_permission
return if has_permission?
flash[:warning] = 'Your account does not have access to this page'
Expand Down
Empty file removed app/mailers/.keep
Empty file.
16 changes: 0 additions & 16 deletions app/mailers/error_mailer.rb

This file was deleted.

Empty file removed app/models/.keep
Empty file.
4 changes: 0 additions & 4 deletions app/views/errors/500.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/replacement_mailer/no_replacement_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<body>
<p>
This is a notification that your reserved Gold Cart (<%= @rental.basic_info %>) has been put on hold by Parking services for the following reason:
This is a notification that your reserved Golf Cart (<%= @rental.basic_info %>) has been put on hold by Parking services for the following reason:
</p>
<p>
<%= @hold.hold_reason %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/replacement_mailer/replacement_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<body>
<p>
This is a notification that your reserved Gold Cart (<%= @old_rental.basic_info %>) has been put on hold by Parking services for the following reason:
This is a notification that your reserved Golf Cart (<%= @old_rental.basic_info %>) has been put on hold by Parking services for the following reason:
</p>
<p>
<%= @hold.hold_reason %>
Expand Down
23 changes: 8 additions & 15 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,14 @@
port: 25
}

config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[ERROR] ",
:sender_address => %{"notifier" <[email protected]>},
:exception_recipients => %w{[email protected]}
},
:slack => {
:webhook_url => "https://hooks.slack.com/services/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",
:channel => "#probably-exceptions",
:additional_parameters => {
:icon_url => "http://image.jpg",
:mrkdwn => true
}
}

# Inventory api url
config.inventory_api_uri = 'https://rentalapi.parking.umass.edu/v1/' # not sure what this is yet
end

GolfCartRentals::Application.config.middleware.use ExceptionNotification::Rack,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just use the config declared above, as in all our other apps. No need to re-declare the GolfCartRentals::Application here.

email: {
email_prefix: "Golf-Cart-Rentals Exception: ",
sender_address: %{"Golf-Cart-Rentals" <[email protected]>},
exception_recipients: %w{[email protected]}

}
4 changes: 1 addition & 3 deletions lib/errors/inventory_exceptions_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def self.included(klass)
private

def error_response(e)
# this module is currently only included in ApplicationController and relies on
# ApplicationController's private `send_error_email` method
send_error_email(e)
ExceptionNotifier.notify_exception(e)
render template: 'errors/inventory_exception.html.erb',
locals: { error_class: e.class, error_message: e.message },
status: 500
Expand Down
143 changes: 86 additions & 57 deletions public/500.html
Original file line number Diff line number Diff line change
@@ -1,66 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<style>
body {
background-color: #efefef;
color: #2e2f30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
div.dialog > div {
border: 1px solid #ccc;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #bbb;
border-top: #b00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
h1 {
font-size: 100%;
color: #730e15;
line-height: 1.5em;
}

div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #f7f7f7;
border: 1px solid #ccc;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #dadada;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>

<body>
<!-- This file lives in public/500.html -->
<div class="dialog">
<div>
<h1>We're sorry, but something went wrong.</h1>
<body>
<!-- This file lives in public/500.html -->
<div class="dialog">
<div>
<h1>
An error occured processing your request. A message has been sent to
IT.
</h1>
</div>
<p>
Please contact UMass Parking Services using the contact information
below to report any additional information.
</p>
<p>
This site is maintained by UMass Amherst Parking Services<br />
413.577.PARK |
<a href="https://parking.umass.edu/" rel="nofollow"
>Parking Home Page</a
>
|
<a href="mailto:[email protected]?Subject=Issue:" target="_top"
>Report An Error</a
>
<br />
©
<script>
document.write(new Date().getFullYear());</script
>2019
<a href="http://www.umass.edu/" rel="nofollow"
>University of Massachusetts Amherst</a
>
|
<a href="http://www.umass.edu/umhome/policies/" rel="nofollow"
>Site Policies</a
>
</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</body>
</html>
16 changes: 0 additions & 16 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,6 @@ def test_no_permission; end
end
end

describe 'when an error occurs' do
before :each do
allow_any_instance_of(ApplicationController).to receive(:root).and_raise('test root error')
end

it 'calls the render_500 method' do
get :root
expect(response).to render_template('errors/500.html.erb')
end

it 'sends an error email' do
expect(subject).to receive(:send_error_email)
get :root
end
end

describe '#root' do
it 'redirects to the home index action' do
get :root
Expand Down
7 changes: 0 additions & 7 deletions spec/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,5 @@
expect(assigns[:rentals]).to contain_exactly @rental, @rental2
end
end

it 'handles an error by sending an email' do
allow_any_instance_of(HomeController).to receive(:index).and_raise(StandardError.new)
# in application controller we rescue exceptions with render 500
expect_any_instance_of(ApplicationController).to receive(:render_500)
get :index
end
end
end
22 changes: 0 additions & 22 deletions spec/mailers/error_mailer_spec.rb

This file was deleted.

Empty file removed vendor/assets/javascripts/.keep
Empty file.