8000 Add Turbolinks-Status header to show custom error page by ypresto · Pull Request #334 · turbolinks/turbolinks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Sep 25, 2021. It is now read-only.

Add Turbolinks-Status header to show custom error page #334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ypresto
Copy link
Contributor
@ypresto ypresto commented Dec 5, 2017

#179

Passing turbolinks: true Calling render method with turbolinks-rails gem will correctly replaces page with error response (non-2xx).

gem PR:
turbolinks/turbolinks-rails#25
turbolinks/turbolinks-rails#35

Copy link
Member
@jeremy jeremy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should have turbolinks-rails always return a response header that indicates a successful Turbolinks page load. Then apps wouldn't need to take on the burden of remembering to return a special "I'm Turbolinks compatible" header on app-generated error responses.

@jeremy
Copy link
Member
jeremy commented Dec 5, 2017

If we always indicated Turbolinks response status:

turbolinks

--- a/src/turbolinks/http_request.coffee
+++ b/src/turbolinks/http_request.coffee
@@ -29,7 +29,7 @@ class Turbolinks.HttpRequest
 
   requestLoaded: =>
     @endRequest =>
-      if 200 <= @xhr.status < 300
+      if 200 <= @xhr.status < 300 or @xhr.getResponseHeader("Turbolinks-Status") is "OK"
         @delegate.requestCompletedWithResponse(@xhr.responseText, @xhr.getResponseHeader("Turbolinks-Location"))
       else
         @failed = true

turbolinks-rails

def render(*)
  super.tap do
    response.headers["Turbolinks-Status"] = "OK"
  end
end

@ypresto ypresto changed the title Add Turbolinks-Force-Success header Add Turbolinks-Status header to show custom error page Jan 15, 2018
@ypresto
Copy link
Contributor Author
ypresto commented Jan 15, 2018

Sorry for late, updated PR..!

@tvandervossen
Copy link
tvandervossen commented Apr 23, 2019

Here’s the same change updated for the recent port to TypeScript:

index 55eba8f..5be0d2a 100644
--- a/src/http_request.ts
+++ b/src/http_request.ts
@@ -68,7 +68,7 @@ export class HttpRequest {
     this.endRequest(xhr => {
       const contentType = xhr.getResponseHeader("Content-Type")
       if (contentTypeIsHTML(contentType)) {
-        if (xhr.status >= 200 && xhr.status < 300) {
+        if (xhr.status >= 200 && xhr.status < 300 || xhr.getResponseHeader("Turbolinks-Status") == 'OK') {
           const redirectedToLocation = Location.wrap(xhr.getResponseHeader("Turbolinks-Location"))
           this.delegate.requestCompletedWithResponse(xhr.responseText, redirectedToLocation)
         } else {

Trying to include this PR with the release of the TypeScript port might save some people a bit of trouble since the TypeScript port is likely to break the monkey patches currently in use to allow Turbolink to work well with custom error pages using the Rails application layout.

@ypresto are you still interesting in trying to move this forward, or would you like me to take over from you?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0