PaperStrike / Pjax

Easily enable fast AJAX navigation (Fetch + pushState)
MIT License
24 stars 3 forks source link

Wrong HTTPS status error messages are displayed in browser / Pjax repeats request even if HTML present #357

Open misog opened 2 years ago

misog commented 2 years ago

Describe the bug

Hi, this issue is caused by Pjax revisits as described here: https://github.com/PaperStrike/Pjax/issues/342

The problem is worse however. For example, when user uploads too large file, the server response "413 Request Entity Too Large" should be displayed to user. For example, this is returned by nginx:

<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>

But now Pjax tries to revisit that URL and that will produce this error instead:

Oops! An Error Occurred
The server returned a "405 Method Not Allowed".

The core of the problem is that Pjax makes additional request without user consent (revisit).

To reproduce

  1. Make any form POST request to URL in a way that generates status code >=400 and where the URL is POST-only
  2. See the error message
  3. The error message is wrong (Pjax tries to GET that URL which is POST-only)

Expected behavior

Possible solutions

Pjax probably checks mime type or something in header or status code to decide if to repeat request.

One solution to this problem is to check if there is any HTML content even if there is error status and then NOT repeat request (revisit) and instead run document.write(htm_error). Or user-provided handler for error output can be run (where I would call document.write and show the HTML of the error message).

PaperStrike commented 1 year ago

Technically a duplicate of #342, it's all about fetch error handling.