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

Handle server errors for form submissions #353

Merged
merged 1 commit into from
Aug 25, 2021
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
6 changes: 5 additions & 1 deletion src/core/drive/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ export class Navigator {

if (responseHTML) {
const snapshot = PageSnapshot.fromHTMLString(responseHTML)
await this.view.renderPage(snapshot)
if (fetchResponse.serverError) {
await this.view.renderError(snapshot)
} else {
await this.view.renderPage(snapshot)
}
this.view.scrollToTop()
this.view.clearSnapshotCache()
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Form</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<style>
<style id="form-fixture-styles">
dialog {
display: block;
position: static;
Expand Down
2 changes: 2 additions & 0 deletions src/tests/functional/form_submission_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ export class FormSubmissionTests extends TurboDriveTestCase {
}

async "test invalid form submission with server error status"() {
this.assert(await this.hasSelector("head > #form-fixture-styles"))
await this.clickSelector("#reject form.internal_server_error input[type=submit]")
await this.nextBody

const title = await this.querySelector("h1")
this.assert.equal(await title.getVisibleText(), "Internal Server Error", "renders the response HTML")
this.assert.notOk(await this.hasSelector("head > #form-fixture-styles"), "replaces head")
this.assert.notOk(await this.hasSelector("#frame form.reject"), "replaces entire page")
}

Expand Down