Viktoriia 10 月之前
父節點
當前提交
6065b5af4d
共有 7 個文件被更改,包括 39 次插入9 次删除
  1. 20 2
      App.tsx
  2. 8 0
      app.config.ts
  3. 4 2
      metro.config.js
  4. 2 0
      package.json
  5. 1 1
      src/database/geojsonService/index.ts
  6. 3 3
      src/db/index.ts
  7. 1 1
      src/utils/mapHelpers.ts

+ 20 - 2
App.tsx

@@ -2,6 +2,7 @@ import 'react-native-gesture-handler';
 import { QueryClientProvider } from '@tanstack/react-query';
 import { NavigationContainer } from '@react-navigation/native';
 import { queryClient } from 'src/utils/queryClient';
+import * as Sentry from '@sentry/react-native';
 
 import Route from './Route';
 import { ConnectionProvider } from 'src/contexts/ConnectionContext';
@@ -12,6 +13,17 @@ import { useEffect } from 'react';
 import { setupInterceptors } from 'src/utils/request';
 import { ErrorModal } from 'src/components';
 import { NotificationProvider } from 'src/contexts/NotificationContext';
+import React from 'react';
+
+const routingInstrumentation = new Sentry.ReactNavigationInstrumentation({
+  enableTimeToInitialDisplay: true
+});
+
+Sentry.init({
+  dsn: 'https://c9b37005f4be22a17a582603ebc17598@o4507781200543744.ingest.de.sentry.io/4507781253824592',
+  integrations: [new Sentry.ReactNativeTracing({ routingInstrumentation })],
+  debug: false
+});
 
 const App = () => {
   return (
@@ -27,6 +39,7 @@ const App = () => {
 
 const InnerApp = () => {
   const errorContext = useError();
+  const navigation = React.useRef(null);
 
   useEffect(() => {
     setupInterceptors(errorContext);
@@ -35,7 +48,12 @@ const InnerApp = () => {
   return (
     <ConnectionProvider>
       <RegionProvider>
-        <NavigationContainer>
+        <NavigationContainer
+          ref={navigation}
+          onReady={() => {
+            routingInstrumentation.registerNavigationContainer(navigation);
+          }}
+        >
           <ConnectionBanner />
           <Route />
           <ErrorModal />
@@ -45,4 +63,4 @@ const InnerApp = () => {
   );
 };
 
-export default App;
+export default Sentry.wrap(App);

+ 8 - 0
app.config.ts

@@ -106,5 +106,13 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
         }
       }
     ],
+    [
+      "@sentry/react-native/expo",
+      {
+        organization: env.SENTRY_ORG,
+        project: env.SENTRY_PROJECT,
+        url: "https://sentry.io/"
+      }
+    ]
   ]
 });

+ 4 - 2
metro.config.js

@@ -1,7 +1,9 @@
-const { getDefaultConfig } = require('expo/metro-config');
+// const { getDefaultConfig } = require('expo/metro-config');
+const { getSentryExpoConfig } = require('@sentry/react-native/metro');
 
 module.exports = (() => {
-  const config = getDefaultConfig(__dirname);
+  // const config = getDefaultConfig(__dirname);
+  const config = getSentryExpoConfig(__dirname);
 
   const { transformer, resolver } = config;
 

+ 2 - 0
package.json

@@ -21,6 +21,7 @@
     "@react-navigation/native": "^6.1.9",
     "@react-navigation/native-stack": "^6.9.17",
     "@react-navigation/stack": "^6.3.20",
+    "@sentry/react-native": "^5.29.0",
     "@shopify/flash-list": "1.4.3",
     "@tanstack/react-query": "latest",
     "@turf/turf": "^6.5.0",
@@ -45,6 +46,7 @@
     "formik": "^2.4.5",
     "moment": "^2.29.4",
     "patch-package": "^8.0.0",
+    "promise": "^8.3.0",
     "react": "18.2.0",
     "react-native": "0.72.10",
     "react-native-animated-pagination-dot": "^0.4.0",

+ 1 - 1
src/database/geojsonService/index.ts

@@ -45,7 +45,7 @@ export const fetchJsonData = async () => {
   try {
     const response = await axios.get(`${API_HOST}/static/json/mqp.geojson`);
     if (response.status !== 200) {
-      throw new Error('Network response error');
+      console.error('Network response error');
     }
     jsonData = response.data;
     await saveJsonDataToLocal(jsonData);

+ 3 - 3
src/db/index.ts

@@ -136,7 +136,7 @@ async function refreshNmDatabase() {
     const nmResponse = await FileSystem.downloadAsync(nmUrl, nmFileUri);
 
     if (nmResponse.status !== 200) {
-      throw new Error(`Failed to download the nmDb file: Status code ${nmResponse.status}`);
+      console.error(`Failed to download the nmDb file: Status code ${nmResponse.status}`);
     }
 
     db1 = null;
@@ -156,7 +156,7 @@ async function refreshDarePlacesDatabase() {
     const dareResponse = await FileSystem.downloadAsync(dareUrl, dareFileUri);
 
     if (dareResponse.status !== 200) {
-      throw new Error(`Failed to download the dareDb file: Status code ${dareResponse.status}`);
+      console.error(`Failed to download the dareDb file: Status code ${dareResponse.status}`);
     }
 
     db2 = null;
@@ -176,7 +176,7 @@ async function refreshCountriesDatabase() {
     const countriesResponse = await FileSystem.downloadAsync(countriesUrl, countriesFileUri);
 
     if (countriesResponse.status !== 200) {
-      throw new Error(
+      console.error(
         `Failed to download the countriesDb file: Status code ${countriesResponse.status}`
       );
     }

+ 1 - 1
src/utils/mapHelpers.ts

@@ -46,7 +46,7 @@ export const calculateMapCountry = (bbox: turf.BBox, center: number[]): any => {
     maxLat === undefined ||
     maxLng === undefined
   ) {
-    throw new Error("Invalid bbox coordinates");
+    console.error("Invalid bbox coordinates");
   }
 
   let latitudeDelta = Math.abs(maxLat - minLat) + padding;