Skip to content
This repository has been archived by the owner on Jul 28, 2018. It is now read-only.

Handle errors during onload by a hard page load #669

Open
wants to merge 1 commit into
base: 2-5-stable
Choose a base branch
from
Open
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
29 changes: 17 additions & 12 deletions lib/assets/javascripts/turbolinks.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ fetchReplacement = (url, onLoadFunction, showProgressBar = true) ->
xhr.setRequestHeader 'Accept', 'text/html, application/xhtml+xml, application/xml'
xhr.setRequestHeader 'X-XHR-Referer', referer

handleError = -> document.location.href = url.absolute

xhr.onload = ->
triggerEvent EVENTS.RECEIVE, url: url.absolute

if doc = processResponse()
reflectNewUrl url
reflectRedirectedUrl()
changePage extractTitleAndBody(doc)...
manuallyTriggerHashChangeForFirefox()
onLoadFunction?()
triggerEvent EVENTS.LOAD
else
document.location.href = crossOriginRedirect() or url.absolute
try
triggerEvent EVENTS.RECEIVE, url: url.absolute

if doc = processResponse()
reflectNewUrl url
reflectRedirectedUrl()
changePage extractTitleAndBody(doc)...
manuallyTriggerHashChangeForFirefox()
onLoadFunction?()
triggerEvent EVENTS.LOAD
else
document.location.href = crossOriginRedirect() or url.absolute
catch
handleError()

if progressBar and showProgressBar
xhr.onprogress = (event) =>
Expand All @@ -80,7 +85,7 @@ fetchReplacement = (url, onLoadFunction, showProgressBar = true) ->
progressBar.advanceTo(percent)

xhr.onloadend = -> xhr = null
xhr.onerror = -> document.location.href = url.absolute
xhr.onerror = handleError

xhr.send()

Expand Down