Skip to content
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

chore(sample): Add Http Client Errors Example to the sample app #2769

Merged
merged 9 commits into from
Jan 23, 2023
10 changes: 10 additions & 0 deletions sample/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {createStackNavigator} from '@react-navigation/stack';

// Import the Sentry React Native SDK
import * as Sentry from '@sentry/react-native';
import * as Integrations from '@sentry/integrations';

import HomeScreen from './screens/HomeScreen';
import TrackerScreen from './screens/TrackerScreen';
Expand Down Expand Up @@ -51,6 +52,15 @@ Sentry.init({
return context;
},
}),
new Integrations.HttpClient({
// This array can contain tuples of `[begin, end]` (both inclusive),
// Single status codes, or a combinations of both.
// default: [[500, 599]]
failedRequestStatusCodes: [[400, 405], [500, 505], 507],
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
// This array can contain Regexes or strings, or combinations of both.
// default: [/.*/]
failedRequestTargets: ['http://localhost'],
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
}),
],
enableAutoSessionTracking: true,
// For testing, session close when 5 seconds (instead of the default 30) in the background.
Expand Down
8 changes: 8 additions & 0 deletions sample/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ const HomeScreen = (props: Props) => {
.then((asset: number[]) => setData(new Uint8Array(asset)));
}, []);

useEffect(() => {
try {
fetch('http://localhost:8081/not-found');
} catch (error) {
//ignore the error, it will be send to Sentry
}
});
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
<StatusBar barStyle="dark-content" />
Expand Down