Pjax icon indicating copy to clipboard operation
Pjax copied to clipboard

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

Open misog opened this issue 3 years ago • 1 comments
trafficstars

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

  • Correct server error message should be displayed in the browser.
  • Pjax should not repeat a request if there is HTML content to show in the first response.

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).

misog avatar Aug 26 '22 09:08 misog

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

PaperStrike avatar Feb 06 '23 05:02 PaperStrike