[Misc] Show a better error message when not authorized

This previously just showed that an unexpected error occured which
isn't very helpful.

See #509
This commit is contained in:
Earlopain 2023-05-07 15:00:26 +02:00
parent 7ed3047621
commit 44485e90fd
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
2 changed files with 2 additions and 2 deletions

View File

@ -66,7 +66,7 @@ class ApplicationController < ActionController::Base
cookies.delete :remember
render_expected_error(401, exception.message)
when ActionController::InvalidAuthenticityToken
render_error_page(403, exception)
render_expected_error(403, "ActionController::InvalidAuthenticityToken. Did you properly authorize your request?")
when ActiveRecord::RecordNotFound
render_404
when ActionController::RoutingError

View File

@ -112,7 +112,7 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
# try to submit a form with cookies but without the csrf token
put user_path(@user), headers: { HTTP_COOKIE: headers["Set-Cookie"] }, params: { user: { enable_safe_mode: "true" } }
assert_response 403
assert_equal("An unexpected error occurred.", css_select("p").first.content)
assert_match(/ActionController::InvalidAuthenticityToken/, css_select("p").first.content)
assert_equal(false, @user.reload.enable_safe_mode)
end
end