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, 599]],
// This array can contain Regexes or strings, or combinations of both.
// default: [/.*/]
failedRequestTargets: [/.*/],
}),
],
enableAutoSessionTracking: true,
// For testing, session close when 5 seconds (instead of the default 30) in the background.
Expand Down
13 changes: 12 additions & 1 deletion sample/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,18 @@ const HomeScreen = (props: Props) => {
<Text style={styles.buttonText}>Get attachment</Text>
</TouchableOpacity>
<View style={styles.spacer} />
<UserFeedbackModal/>
<UserFeedbackModal />
<View style={styles.spacer} />
<TouchableOpacity
onPress={async () => {
try {
fetch('http://localhost:8081/not-found');
} catch (error) {
//ignore the error, it will be send to Sentry
}
}}>
<Text style={styles.buttonText}>Capture HTTP Client Error</Text>
</TouchableOpacity>
</View>
<View style={styles.buttonArea}>
<TouchableOpacity
Expand Down