brouillon: redirect to sign-in when disconnected

There are two cases where the draft auto-save might fail because the
user is no longer authenticated:

- The user signed-out in another tab,
- The brower quit and re-opened, so the Session cookie expired.

In both cases, the auto-save will never succeed until the user
authenticates again, so displaying a "Retry" button is cruel.

Moreover, in plus of all auto-save requests failing with a small error,
the actual hard failure only occurs after filling all the form and
trying to submit it. Then the user is redirected to the sign-in page –
but all their changes are lost.

Instead, we now redirect to the sign-in page on the first 401 error
during the auto-save, let the user sign-in, and then redirect back to
the form.
This commit is contained in:
Pierre de La Morinerie 2021-07-22 08:31:13 +00:00
parent 7808f6dd4f
commit e1909ed29f
3 changed files with 47 additions and 3 deletions

View file

@ -47,3 +47,16 @@ Capybara::Screenshot.prune_strategy = :keep_last_run
Capybara::Screenshot.register_driver :headless_chrome do |driver, path|
driver.browser.save_screenshot(path)
end
RSpec.configure do |config|
# Examples tagged with :capybara_ignore_server_errors will allow Capybara
# to continue when an exception in raised by Rails.
# This allows to test for error cases.
config.around(:each, :capybara_ignore_server_errors) do |example|
Capybara.raise_server_errors = false
example.run
ensure
Capybara.raise_server_errors = true
end
end