fix: page.goto error throwing on 40x/50x responses with an empty body (#9523) (#9577)

Co-authored-by: Alex Rudenko <OrKoN@users.noreply.github.com>
This commit is contained in:
Rafael Martins 2023-02-06 06:40:51 -03:00 committed by GitHub
parent 9b11b6a4e0
commit ddb0cc174d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -354,6 +354,9 @@ export class Frame {
referrerPolicy, referrerPolicy,
}); });
ensureNewDocumentNavigation = !!response.loaderId; ensureNewDocumentNavigation = !!response.loaderId;
if (response.errorText === 'net::ERR_HTTP_RESPONSE_CODE_FAILURE') {
return null;
}
return response.errorText return response.errorText
? new Error(`${response.errorText} at ${url}`) ? new Error(`${response.errorText} at ${url}`)
: null; : null;

View File

@ -304,6 +304,30 @@ describe('navigation', function () {
expect(response.ok()).toBe(false); expect(response.ok()).toBe(false);
expect(response.status()).toBe(404); expect(response.status()).toBe(404);
}); });
it('should not throw an error for a 404 response with an empty body', async () => {
const {page, server} = getTestState();
server.setRoute('/404-error', (_, res) => {
res.statusCode = 404;
res.end();
});
const response = (await page.goto(server.PREFIX + '/404-error'))!;
expect(response.ok()).toBe(false);
expect(response.status()).toBe(404);
});
it('should not throw an error for a 500 response with an empty body', async () => {
const {page, server} = getTestState();
server.setRoute('/500-error', (_, res) => {
res.statusCode = 500;
res.end();
});
const response = (await page.goto(server.PREFIX + '/500-error'))!;
expect(response.ok()).toBe(false);
expect(response.status()).toBe(500);
});
it('should return last response in redirect chain', async () => { it('should return last response in redirect chain', async () => {
const {page, server} = getTestState(); const {page, server} = getTestState();