Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error to Bugsnag for StandardError #5569

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ApplicationController < ActionController::Base
after_action :verify_authorized, except: :index, unless: :devise_controller?
# after_action :verify_policy_scoped, only: :index

KNOWN_ERRORS = [Pundit::NotAuthorizedError, Organizational::UnknownOrganization]
rescue_from StandardError, with: :log_and_reraise
rescue_from Pundit::NotAuthorizedError, with: :not_authorized
rescue_from Organizational::UnknownOrganization, with: :not_authorized

Expand Down Expand Up @@ -136,6 +138,13 @@ def not_authorized
redirect_to(root_url)
end

def log_and_reraise(error)
unless KNOWN_ERRORS.include?(error.class)
Bugsnag.notify(error)
end
raise
end

def check_unconfirmed_email_notice(user)
notice = "#{user.role} was successfully updated."
if user.saved_changes.include?("unconfirmed_email")
Expand Down
2 changes: 1 addition & 1 deletion public/403.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<title>We're sorry, but something went wrong (403)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
Expand Down
21 changes: 13 additions & 8 deletions spec/lib/tasks/volunteer_birthday_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

RSpec.describe "lib/tasks/volunteer_birthday_reminder.rake" do
let(:rake_task) { Rake::Task["volunteer_birthday_reminder"].invoke }
let(:now) { Date.new(2022, 10, 15) }
let(:this_month) { now.month }
let(:this_month_15th) { Date.new(now.year, now.month, 15) }
let(:next_month) { Date.new(1988, this_month + 1, 1) }
let(:not_next_month) { Date.new(1998, this_month - 1, 1) }

before do
Rake::Task.clear
Casa::Application.load_tasks

travel_to Date.new(2022, 10, 15)
travel_to now
end

after do
Expand All @@ -18,7 +23,7 @@

context "there is a volunteer with a birthday next month" do
let!(:volunteer) do
create(:volunteer, :with_assigned_supervisor, date_of_birth: Date.new(1988, 11, 30))
create(:volunteer, :with_assigned_supervisor, date_of_birth: next_month)
end

it "creates a notification" do
Expand All @@ -29,7 +34,7 @@
context "there are many volunteers with birthdays next month" do
volunteer_count = 10
let!(:volunteer) do
create_list(:volunteer, volunteer_count, :with_assigned_supervisor, date_of_birth: Date.new(1988, 11, 30))
create_list(:volunteer, volunteer_count, :with_assigned_supervisor, date_of_birth: next_month)
end

it "creates many notifications" do
Expand All @@ -39,7 +44,7 @@

context "there is an unsupervised volunteer with a birthday next month" do
let!(:volunteer) do
create(:volunteer, date_of_birth: Date.new(1988, 11, 30))
create(:volunteer, date_of_birth: next_month)
end

it "does not create a notification" do
Expand All @@ -59,7 +64,7 @@

context "there is a volunteer with a birthday that is not next month" do
let!(:volunteer) do
create(:volunteer, :with_assigned_supervisor, date_of_birth: Date.new(1998, 7, 16))
create(:volunteer, :with_assigned_supervisor, date_of_birth: not_next_month)
end

it "does not create a notification" do
Expand All @@ -68,10 +73,10 @@
end

context "when today is the 15th" do
before { travel_to(Date.new(2022, 10, 15)) }
before { travel_to(this_month_15th) }

let!(:volunteer) do
create(:volunteer, :with_assigned_supervisor, date_of_birth: Date.new(1988, 11, 30))
create(:volunteer, :with_assigned_supervisor, date_of_birth: next_month)
end

it "runs the rake task" do
Expand All @@ -80,7 +85,7 @@
end

context "when today is not the 15th" do
before { travel_to(Date.new(2022, 10, 1)) }
before { travel_to(this_month_15th + 2.days) }

it "skips the rake task" do
expect { rake_task }.to change { Notification.count }.by(0)
Expand Down
Loading