This is typical scenario: a page is evaluated, and there's a buffer - once the buffer is full, the part of the page that is evaluated is sent to the browser. This uses the HTTP 1.1 chunked encoding.
However, an error can occur in one of the chunks (after the first one is already sent). In that case:
- you can't redirect (send a
Location
header), because the headers and the response status were already sent - you can't do server-side redirect (forward), because the new page will have to be rendered after the part that is already sent - it will look ugly for sure.
So what should you do in this case? I asked a question whether you can send a Location header in the chunked trailer, but this is low-level http and the abstraction of languages may not allow it, even if it is possible (and it is likely not to be supported across browsers)
Another option is to send a <script>window.href.location="errorPage"</script>
and thus force the client to redirect, but that's ugly. Plus you have to put </script>
to close any potential unclosed <script>
tag in the partial page.
(I'm tagging major web languages/frameworks, because this is an universal issue)