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 turbo:fetch-request-error event on frame and form network errors #640

Merged
merged 17 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 0 deletions src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FetchResponse } from "../../http/fetch_response"
import { expandURL } from "../url"
import { dispatch, getMetaContent } from "../../util"
import { StreamMessage } from "../streams/stream_message"
import { TurboFetchErrorEvent } from "../session"

export interface FormSubmissionDelegate {
formSubmissionStarted(formSubmission: FormSubmission): void
Expand Down Expand Up @@ -199,6 +200,11 @@ export class FormSubmission {

requestErrored(request: FetchRequest, error: Error) {
this.result = { success: false, error }
dispatch<TurboFetchErrorEvent>("turbo:fetch-error", {
target: this.formElement,
detail: { request, error },
cancelable: true,
srt32 marked this conversation as resolved.
Show resolved Hide resolved
})
this.delegate.formSubmissionErrored(this, error)
}

Expand Down
7 changes: 6 additions & 1 deletion src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { FrameRenderer } from "./frame_renderer"
import { session } from "../index"
import { isAction, Action } from "../types"
import { VisitOptions } from "../drive/visit"
import { TurboBeforeFrameRenderEvent } from "../session"
import { TurboBeforeFrameRenderEvent, TurboFetchErrorEvent } from "../session"

export class FrameController
implements
Expand Down Expand Up @@ -241,6 +241,11 @@ export class FrameController

requestErrored(request: FetchRequest, error: Error) {
console.error(error)
dispatch<TurboFetchErrorEvent>("turbo:fetch-error", {
srt32 marked this conversation as resolved.
Show resolved Hide resolved
target: this.element,
detail: { request, error },
cancelable: true,
srt32 marked this conversation as resolved.
Show resolved Hide resolved
})
this.resolveVisitPromise()
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { FrameElement } from "../elements/frame_element"
import { FrameViewRenderOptions } from "./frames/frame_view"
import { FetchResponse } from "../http/fetch_response"
import { Preloader, PreloaderDelegate } from "./drive/preloader"
import { FetchRequest } from "../http/fetch_request"

export type TimingData = unknown
export type TurboBeforeCacheEvent = CustomEvent
Expand All @@ -29,6 +30,7 @@ export type TurboBeforeVisitEvent = CustomEvent<{ url: string }>
export type TurboClickEvent = CustomEvent<{ url: string; originalEvent: MouseEvent }>
export type TurboFrameLoadEvent = CustomEvent
export type TurboBeforeFrameRenderEvent = CustomEvent<{ newFrame: FrameElement } & FrameViewRenderOptions>
export type TurboFetchErrorEvent = CustomEvent<{ request: FetchRequest; error: Error }>
export type TurboFrameRenderEvent = CustomEvent<{ fetchResponse: FetchResponse }>
export type TurboLoadEvent = CustomEvent<{ url: string; timing: TimingData }>
export type TurboRenderEvent = CustomEvent
Expand Down