Skip to content

Commit 1cab46b

Browse files
committed
reproduction: httpclient integration & axios
1 parent 776d9ce commit 1cab46b

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

packages/browser-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"dependencies": {
4747
"@babel/preset-typescript": "^7.16.7",
4848
"@playwright/test": "^1.31.1",
49+
"axios": "1.3.4",
4950
"babel-loader": "^8.2.2",
5051
"html-webpack-plugin": "^5.5.0",
5152
"pako": "^2.1.0",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import axios from 'axios';
2+
3+
axios.get('http://localhost:7654/foo').then(response => {
4+
console.log(response.data);
5+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest(
8+
'should assign request and response context from a failed 500 XHR request',
9+
async ({ getLocalTestPath, page }) => {
10+
const url = await getLocalTestPath({ testDir: __dirname });
11+
12+
await page.route('**/foo', route => {
13+
return route.fulfill({
14+
status: 500,
15+
body: JSON.stringify({
16+
error: {
17+
message: 'Internal Server Error',
18+
},
19+
}),
20+
headers: {
21+
'Content-Type': 'text/html',
22+
},
23+
});
24+
});
25+
26+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
27+
28+
expect(eventData.exception?.values).toHaveLength(1);
29+
30+
// Not able to get the cookies from the request/response because of Playwright bug
31+
// https://github.com/microsoft/playwright/issues/11035
32+
expect(eventData).toMatchObject({
33+
message: 'HTTP Client Error with status code: 500',
34+
exception: {
35+
values: [
36+
{
37+
type: 'Error',
38+
value: 'HTTP Client Error with status code: 500',
39+
mechanism: {
40+
type: 'http.client',
41+
handled: true,
42+
},
43+
},
44+
],
45+
},
46+
request: {
47+
url: 'http://localhost:7654/foo',
48+
method: 'GET',
49+
headers: {
50+
Accept: 'application/json',
51+
Cache: 'no-cache',
52+
'Content-Type': 'application/json',
53+
},
54+
},
55+
contexts: {
56+
response: {
57+
status_code: 500,
58+
body_size: 45,
59+
headers: {
60+
'content-type': 'text/html',
61+
'content-length': '45',
62+
},
63+
},
64+
},
65+
});
66+
},
67+
);

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6686,6 +6686,15 @@ aws4@^1.8.0:
66866686
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
66876687
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
66886688

6689+
[email protected], axios@^1.2.2:
6690+
version "1.3.4"
6691+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.4.tgz#f5760cefd9cfb51fd2481acf88c05f67c4523024"
6692+
integrity sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==
6693+
dependencies:
6694+
follow-redirects "^1.15.0"
6695+
form-data "^4.0.0"
6696+
proxy-from-env "^1.1.0"
6697+
66896698
axios@^0.27.2:
66906699
version "0.27.2"
66916700
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
@@ -6703,15 +6712,6 @@ axios@^1.0.0:
67036712
form-data "^4.0.0"
67046713
proxy-from-env "^1.1.0"
67056714

6706-
axios@^1.2.2:
6707-
version "1.3.4"
6708-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.4.tgz#f5760cefd9cfb51fd2481acf88c05f67c4523024"
6709-
integrity sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==
6710-
dependencies:
6711-
follow-redirects "^1.15.0"
6712-
form-data "^4.0.0"
6713-
proxy-from-env "^1.1.0"
6714-
67156715
babel-code-frame@^6.26.0:
67166716
version "6.26.0"
67176717
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"

0 commit comments

Comments
 (0)