mirror of
https://github.com/microsoft/playwright.git
synced 2024-09-11 20:37:54 +03:00
chore(fetch): include response text into failOnStatusCode errors (#31978)
Fixes https://github.com/microsoft/playwright/issues/31834
This commit is contained in:
parent
5a83fe55bc
commit
db0980a850
@ -214,8 +214,16 @@ export abstract class APIRequestContext extends SdkObject {
|
||||
});
|
||||
const fetchUid = this._storeResponseBody(fetchResponse.body);
|
||||
this.fetchLog.set(fetchUid, controller.metadata.log);
|
||||
if (params.failOnStatusCode && (fetchResponse.status < 200 || fetchResponse.status >= 400))
|
||||
throw new Error(`${fetchResponse.status} ${fetchResponse.statusText}`);
|
||||
if (params.failOnStatusCode && (fetchResponse.status < 200 || fetchResponse.status >= 400)) {
|
||||
let responseText = '';
|
||||
if (fetchResponse.body.byteLength) {
|
||||
let text = fetchResponse.body.toString('utf8');
|
||||
if (text.length > 1000)
|
||||
text = text.substring(0, 997) + '...';
|
||||
responseText = `\nResponse text:\n${text}`;
|
||||
}
|
||||
throw new Error(`${fetchResponse.status} ${fetchResponse.statusText}${responseText}`);
|
||||
}
|
||||
return { ...fetchResponse, fetchUid };
|
||||
}
|
||||
|
||||
|
@ -145,6 +145,8 @@ for (const method of ['fetch', 'delete', 'get', 'head', 'patch', 'post', 'put']
|
||||
failOnStatusCode: true
|
||||
}).catch(e => e);
|
||||
expect(error.message).toContain('404 Not Found');
|
||||
if (method !== 'head')
|
||||
expect(error.message).toContain('Response text:\nFile not found:');
|
||||
});
|
||||
|
||||
it(`${method}should support ignoreHTTPSErrors option`, async ({ context, httpsServer }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user