diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.ts index e581970ff7..4885a3245d 100644 --- a/packages/playwright-core/src/server/fetch.ts +++ b/packages/playwright-core/src/server/fetch.ts @@ -208,7 +208,7 @@ export abstract class APIRequestContext extends SdkObject { }); const fetchUid = this._storeResponseBody(fetchResponse.body); this.fetchLog.set(fetchUid, controller.metadata.log); - let failOnStatusCode = params.failOnStatusCode !== undefined ? params.failOnStatusCode : !!defaults.apiRequest?.failOnStatusCode; + const failOnStatusCode = params.failOnStatusCode !== undefined ? params.failOnStatusCode : !!defaults.apiRequest?.failOnStatusCode; if (failOnStatusCode && (fetchResponse.status < 200 || fetchResponse.status >= 400)) { let responseText = ''; if (fetchResponse.body.byteLength) { @@ -665,7 +665,7 @@ export class GlobalAPIRequestContext extends APIRequestContext { baseURL: options.baseURL, userAgent: options.userAgent || getUserAgent(), extraHTTPHeaders: options.extraHTTPHeaders, - apiRequest: {failOnStatusCode: !!options.apiRequest?.failOnStatusCode}, + apiRequest: { failOnStatusCode: !!options.apiRequest?.failOnStatusCode }, ignoreHTTPSErrors: !!options.ignoreHTTPSErrors, httpCredentials: options.httpCredentials, clientCertificates: options.clientCertificates, diff --git a/tests/library/global-fetch.spec.ts b/tests/library/global-fetch.spec.ts index e00df5d928..004f459b64 100644 --- a/tests/library/global-fetch.spec.ts +++ b/tests/library/global-fetch.spec.ts @@ -545,7 +545,7 @@ it('should throw when failOnStatusCode is set to true', async ({ playwright, ser res.end('Not found.'); }); const error = await request.fetch(server.EMPTY_PAGE).catch(e => e); - expect(error.message).toContain('404 Not Found') + expect(error.message).toContain('404 Not Found'); }); it('should throw when failOnStatusCode is set to true inside the fetch API call', async ({ playwright, server }) => { @@ -555,8 +555,8 @@ it('should throw when failOnStatusCode is set to true inside the fetch API call' res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); res.end('Not found.'); }); - const error = await request.fetch(server.EMPTY_PAGE, {failOnStatusCode: true}).catch(e => e); - expect(error.message).toContain('404 Not Found') + const error = await request.fetch(server.EMPTY_PAGE, { failOnStatusCode: true }).catch(e => e); + expect(error.message).toContain('404 Not Found'); }); it('should not throw when failOnStatusCode is set to false', async ({ playwright, server }) => { @@ -567,7 +567,7 @@ it('should not throw when failOnStatusCode is set to false', async ({ playwright res.end('Not found.'); }); const error = await request.fetch(server.EMPTY_PAGE).catch(e => e); - expect(error.message).toBeUndefined() + expect(error.message).toBeUndefined(); }); it('should not throw when failOnStatusCode is set to false inside the fetch API call', async ({ playwright, server }) => { @@ -577,6 +577,6 @@ it('should not throw when failOnStatusCode is set to false inside the fetch API res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); res.end('Not found.'); }); - const error = await request.fetch(server.EMPTY_PAGE, {failOnStatusCode: false}).catch(e => e); - expect(error.message).toBeUndefined() + const error = await request.fetch(server.EMPTY_PAGE, { failOnStatusCode: false }).catch(e => e); + expect(error.message).toBeUndefined(); });