-
Notifications
You must be signed in to change notification settings - Fork 27
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
Refactor error handling #4856
base: master
Are you sure you want to change the base?
Refactor error handling #4856
Conversation
4b0e849
to
6df5639
Compare
Also run `rails g controller errors not_found internal_server_error`
6df5639
to
90d4c13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job here!
Left a bunch of comments, basically the same one I copy pasted so I could point to the right lines
def with_dropped_params(&) | ||
QuietStrongParams.with_dropped_params(&) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change automatically done by the linter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I didn't change this line
if current_user | ||
render "errors/forbidden", status: :forbidden | ||
else | ||
redirect_to new_user_session_path, alert: "You need to login to access this page." and return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to return
? Is it the same as doing this?
redirect_to new_user_session_path, alert: "You need to login to access this page." and return | |
return redirect_to new_user_session_path, alert: "You need to login to access this page." |
spec/controller_spec_helper.rb
Outdated
if login | ||
it_should_require_login | ||
else | ||
it do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add some text here?
spec/controller_spec_helper.rb
Outdated
if login | ||
it_should_require_login | ||
else | ||
it do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add some text here?
@@ -100,8 +94,7 @@ def do_request | |||
|
|||
it "does not allow the purchaser" do | |||
sign_in purchaser | |||
do_request | |||
expect(response.status).to eq(403) | |||
expect { do_request }.to raise_error(CanCan::AccessDenied) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the shared example here?
@@ -58,8 +58,7 @@ | |||
visit facility_user_accounts_path("all", new_user) | |||
expect(page).not_to have_content("Clone") | |||
|
|||
visit facility_user_clone_account_memberships_path("all", new_user) | |||
expect(page.status_code).to eq(403) | |||
expect { visit facility_user_clone_account_memberships_path("all", new_user) }.to raise_error(CanCan::AccessDenied) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the shared example here?
end | ||
|
||
it "does not have a remove link present" do | ||
expect { visit facility_price_groups_path(facility) }.to raise_error(CanCan::AccessDenied) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the shared example here?
@@ -80,8 +80,7 @@ | |||
|
|||
it "cannot view the page" do | |||
expect(reservation.order_detail).not_to be_problem | |||
visit edit_problem_reservation_path(reservation) | |||
expect(page.status_code).to eq(404) | |||
expect { visit edit_problem_reservation_path(reservation) }.to raise_error(ActiveRecord::RecordNotFound) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the shared example here?
@@ -99,8 +98,7 @@ | |||
|
|||
it "cannot view the page" do | |||
expect(reservation.order_detail).to be_problem | |||
visit edit_problem_reservation_path(reservation) | |||
expect(page.status_code).to eq(404) | |||
expect { visit edit_problem_reservation_path(reservation) }.to raise_error(ActiveRecord::RecordNotFound) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the shared example here?
@@ -117,8 +117,7 @@ | |||
visit sanger_sequencing_submission_path(SangerSequencing::Submission.last) | |||
expect(page.status_code).to eq(200) | |||
|
|||
visit edit_sanger_sequencing_submission_path(SangerSequencing::Submission.last) | |||
expect(page.status_code).to eq(404) | |||
expect { visit edit_sanger_sequencing_submission_path(SangerSequencing::Submission.last) }.to raise_error(ActiveRecord::RecordNotFound) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the shared example here?
Some specs are failing 😢 |
7e0dc50
to
6be2b80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 💪
if current_user | ||
render "errors/forbidden", status: :forbidden | ||
else | ||
return redirect_to new_user_session_path, alert: "You need to login to access this page." | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change necessary? It's not clear to me why if there's a current user an error is renderd and if not a redirection to login is done
config/application.rb
Outdated
@@ -80,6 +79,10 @@ class Application < Rails::Application | |||
# Prevent invalid (usually malicious) URLs from causing exceptions/issues | |||
config.middleware.insert 0, Rack::UTF8Sanitizer | |||
|
|||
config.action_dispatch.rescue_responses["NUCore::PermissionDenied"] = :forbidden |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also add CanCan::AccessDenied
dffdb67
to
d0dd51f
Compare
515ab8b
to
4b96a5c
Compare
a395609
to
6d5fcc7
Compare
spec/system/kiosk_view_spec.rb
Outdated
@@ -2,7 +2,7 @@ | |||
|
|||
require "rails_helper" | |||
|
|||
RSpec.describe "Launching Kiosk View", :js, feature_setting: { kiosk_view: true, bypass_kiosk_auth: false } do | |||
RSpec.describe "Launching Kiosk View", :js, :disable_requests_local, :show_rescuable_exceptions, feature_setting: { kiosk_view: true, bypass_kiosk_auth: false } do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the :show_rescuable_exceptions
hook is no longer defined
Release Notes
Refactor for how errors are being handled in the app.
It consists of adding an error controller with a method for each error type, adding routes to derivate each exception to the respective controller method, and setting up the exception app to use the routes.
Also updated controller tests to check if exceptions are being raised instead of checking that pages are being rendered.