Skip to content

feat: capture client error in the network interceptor #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1ddc5e3
feat(example): add apm screen (#1141)
abdelhamid-f-nasser Jul 17, 2024
0222c64
fix(android): resolve an OOM in network logs (#1244)
a7medev Jul 18, 2024
635cd47
fix(android): APM network logging(#1253)
kholood-ea Jul 23, 2024
61e1f3f
feat/support-capture-client-error-in-xhr-requests
ahmedAlaaInstabug Jul 24, 2024
50bc3be
feat/support-capture-client-error-in-xhr-requests
ahmedAlaaInstabug Jul 24, 2024
9b23d7a
fix: Pr comments
ahmedAlaaInstabug Jul 29, 2024
99ce7c8
fix: Pr comments
ahmedAlaaInstabug Jul 29, 2024
d8d43eb
fix: Pr comments
ahmedAlaaInstabug Jul 30, 2024
5864aac
fix: Pr comments
ahmedAlaaInstabug Jul 30, 2024
faa33ed
fix: Pr comments
ahmedAlaaInstabug Jul 31, 2024
d00c708
fix: Pr comments
ahmedAlaaInstabug Jul 31, 2024
a53508c
fix: Pr comments
ahmedAlaaInstabug Jul 31, 2024
13ac3ad
fix: Pr comments
ahmedAlaaInstabug Jul 31, 2024
3078211
feat: export upload utils (#1252)
a7medev Jul 31, 2024
6eaf496
chore(example): remove flipper (#1259)
a7medev Jul 31, 2024
f2197b8
fix: Pr comments
ahmedAlaaInstabug Aug 1, 2024
79afb4b
fix(android): resolve an OOM in network logs (#1244)
a7medev Jul 18, 2024
61274de
fix(android): APM network logging(#1253)
kholood-ea Jul 23, 2024
36c9974
feat: export upload utils (#1252)
a7medev Jul 31, 2024
8677585
fix(android): pass network start time in microseconds (#1260)
ahmedAlaaInstabug Aug 2, 2024
b638d12
feat: support feature flags with variants (#1230)
ahmedAlaaInstabug Aug 2, 2024
27a10e3
chore(android): bump android sdk to v13.3.0 (#1261)
a7medev Aug 4, 2024
f5f64f8
chore(ios): bump sdk to v13.3.0 (#1262)
a7medev Aug 4, 2024
2485fac
release: v13.3.0 (#1263)
a7medev Aug 4, 2024
f66f3e1
chore: remove duplicate app flows entries in changelog (#1264)
a7medev Aug 4, 2024
efe4240
chore: remove duplicate execution traces deprecation in changelog (#1…
a7medev Aug 4, 2024
be8daf0
feat: add axios button to example app
ahmedAlaaInstabug Aug 6, 2024
8f0a5c4
fix: change client error code to 9876
ahmedAlaaInstabug Aug 22, 2024
398262d
fix: change client error code to 9876
ahmedAlaaInstabug Aug 22, 2024
ac2d7e6
fix: change client error code to 9876
ahmedAlaaInstabug Aug 22, 2024
9550ce9
fix: change client error code to 9876
ahmedAlaaInstabug Aug 22, 2024
b41ff4f
feat: navigation tracking support with expo router (#1270)
kholood-ea Aug 12, 2024
10286cd
chore: enhance expo router tracking support (#1272)
kholood-ea Aug 13, 2024
ef5a023
ci: generalize enterprise releases (#1275)
a7medev Aug 22, 2024
253c92c
ci: run tests before enterprise releases (#1271)
a7medev Aug 22, 2024
030fa97
ci: publish snapshots to npm (#1274)
a7medev Aug 22, 2024
ee836a1
fix: changelog merge issues
ahmedAlaaInstabug Sep 12, 2024
97350b4
fix: changelog merge issues
ahmedAlaaInstabug Sep 12, 2024
0a16c77
fix: PR comments
ahmedAlaaInstabug Sep 12, 2024
f0c4228
Merge remote-tracking branch 'origin/dev' into sqqq
ahmedAlaaInstabug Sep 15, 2024
b1424be
fix: merge issues
ahmedAlaaInstabug Sep 15, 2024
c189b2b
Merge remote-tracking branch 'origin/dev' into feat/support-capture-c…
ahmedAlaaInstabug Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Add support for Expo Router navigation tracking ([#1270](https://github.com/Instabug/Instabug-React-Native/pull/1270)).
- Enhance the network interceptor to capture more client error messages ([#1257](https://github.com/Instabug/Instabug-React-Native/pull/1257)).

### Fixed

Expand Down
1 change: 1 addition & 0 deletions examples/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@react-navigation/native": "^6.1.6",
"@react-navigation/native-stack": "^6.9.12",
"graphql": "^16.8.1",
"axios": "^1.7.4",
"graphql-request": "^6.1.0",
"instabug-reactnative": "link:../..",
"instabug-reactnative-ndk": "github:https://github.com/Instabug/Instabug-React-Native-NDK",
Expand Down
32 changes: 32 additions & 0 deletions examples/default/src/screens/apm/NetworkScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useQuery } from 'react-query';
import { HStack, VStack } from 'native-base';
import { gql, request } from 'graphql-request';
import { CustomButton } from '../../components/CustomButton';
import axios from 'axios';

export const NetworkScreen: React.FC = () => {
const [endpointUrl, setEndpointUrl] = useState('');
Expand Down Expand Up @@ -45,6 +46,32 @@ export const NetworkScreen: React.FC = () => {
}
}

async function sendRequestToUrlUsingAxios() {
let urlToSend = '';

if (endpointUrl.trim() !== '') {
urlToSend = endpointUrl;
console.log('Sending request to: ', endpointUrl);
} else {
// Use json placeholder URL as a default if endpointUrl is empty
console.log('sending request to default json placeholder');
urlToSend = defaultRequestUrl;
}

try {
// Perform the request using the urlToSend
const response = await axios.get(urlToSend);
// Format the JSON response for better logging
const formattedData = JSON.stringify(response.data, null, 2);

// Log the formatted response
console.log('Response:', formattedData);
} catch (error) {
// Handle errors appropriately
console.error('Error:', error);
}
}

const fetchGraphQlData = async () => {
const document = gql`
query {
Expand Down Expand Up @@ -75,6 +102,11 @@ export const NetworkScreen: React.FC = () => {
value={endpointUrl}
/>
<CustomButton onPress={sendRequestToUrl} title="Send Request To Url" />
<CustomButton
onPress={sendRequestToUrlUsingAxios}
title="Send Request To Url Using Axios"
/>

<CustomButton onPress={() => refetch} title="Reload GraphQL" />
<View>
{isLoading && <Text>Loading...</Text>}
Expand Down
50 changes: 48 additions & 2 deletions examples/default/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3239,11 +3239,25 @@ async@^3.2.2:
resolved "https://registry.yarnpkg.com/async/-/async-3.2.4.tgz#2d22e00f8cddeb5fde5dd33522b56d1cf569a81c"
integrity sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

at-least-node@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==

axios@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.4.tgz#4c8ded1b43683c8dd362973c393f3ede24052aa2"
integrity sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
Expand Down Expand Up @@ -3729,6 +3743,13 @@ colorette@^1.0.7:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40"
integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"

command-exists@^1.2.8:
version "1.2.9"
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69"
Expand Down Expand Up @@ -3941,6 +3962,11 @@ define-data-property@^1.1.1:
gopd "^1.0.1"
has-property-descriptors "^1.0.0"

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

denodeify@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/denodeify/-/denodeify-1.2.1.tgz#3a36287f5034e699e7577901052c2e6c94251631"
Expand Down Expand Up @@ -4329,6 +4355,20 @@ flow-parser@^0.206.0:
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.206.0.tgz#f4f794f8026535278393308e01ea72f31000bfef"
integrity sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w==

follow-redirects@^1.15.6:
version "1.15.6"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

[email protected]:
version "0.5.2"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
Expand Down Expand Up @@ -4650,7 +4690,8 @@ inline-style-prefixer@^6.0.1:
resolved "https://codeload.github.com/Instabug/Instabug-React-Native-NDK/tar.gz/3b0bac281253133852d32f52aa50cc805dd0b570"

"instabug-reactnative@link:../..":
version "13.0.5"
version "0.0.0"
uid ""

intl-messageformat@^10.1.0:
version "10.5.0"
Expand Down Expand Up @@ -6105,7 +6146,7 @@ [email protected], "mime-db@>= 1.43.0 < 2":
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

mime-types@^2.1.27, mime-types@~2.1.34:
mime-types@^2.1.12, mime-types@^2.1.27, mime-types@~2.1.34:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
Expand Down Expand Up @@ -6664,6 +6705,11 @@ proper-lockfile@^3.0.2:
retry "^0.12.0"
signal-exit "^3.0.2"

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down
18 changes: 16 additions & 2 deletions src/utils/XhrNetworkInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export default {
originalXHROpen = XMLHttpRequest.prototype.open;
originalXHRSend = XMLHttpRequest.prototype.send;
originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;

// An error code that signifies an issue with the RN client.
const clientErrorCode = 9876;
XMLHttpRequest.prototype.open = function (method, url, ...args) {
_reset();
network.url = url;
Expand Down Expand Up @@ -145,14 +146,24 @@ export default {

// @ts-ignore
if (this._hasError) {
cloneNetwork.errorCode = 0;
cloneNetwork.errorCode = clientErrorCode;
cloneNetwork.errorDomain = 'ClientError';

// @ts-ignore
const _response = this._response;
cloneNetwork.requestBody =
typeof _response === 'string' ? _response : JSON.stringify(_response);
cloneNetwork.responseBody = '';

// Detect a more descriptive error message.
if (typeof _response === 'string' && _response.length > 0) {
cloneNetwork.errorDomain = _response;
}

// @ts-ignore
} else if (this._timedOut) {
cloneNetwork.errorCode = clientErrorCode;
cloneNetwork.errorDomain = 'TimeOutError';
}

if (this.response) {
Expand All @@ -162,6 +173,9 @@ export default {
} else if (['text', '', 'json'].includes(this.responseType)) {
cloneNetwork.responseBody = JSON.stringify(this.response);
}
} else {
cloneNetwork.responseBody = '';
cloneNetwork.contentType = 'text/plain';
}

cloneNetwork.requestBodySize = cloneNetwork.requestBody.length;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/XhrNetworkInterceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe('Network Interceptor', () => {
expect(callback).toBeCalledWith(
expect.objectContaining({
errorDomain: 'ClientError',
errorCode: 0,
errorCode: 9876,
responseBody: '',
}),
);
Expand Down