diff --git a/src/api/general.ts b/src/api/general.ts index 24b1ef6a..a39f815e 100644 --- a/src/api/general.ts +++ b/src/api/general.ts @@ -58,16 +58,7 @@ const apiGeneral = async ({ }) }) .catch(error => { - // if (sentry && Math.random() < 0.01) { - // Sentry.Native.setExtras({ - // API: 'general', - // ...(error.response && { response: error.response }), - // ...(error.request && { request: error.request }) - // }) - // Sentry.Native.captureException(error) - // } - - if (error.response) { + if (error?.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.error( @@ -80,7 +71,7 @@ const apiGeneral = async ({ status: error.response.status, message: error.response.data.error }) - } else if (error.request) { + } else if (error?.request) { // The request was made but no response was received // `error.request` is an instance of XMLHttpRequest in the browser and an instance of // http.ClientRequest in node.js @@ -94,7 +85,7 @@ const apiGeneral = async ({ console.error( ctx.bold(' API general '), ctx.bold('internal'), - error.message, + error?.message, url ) return Promise.reject() diff --git a/src/api/instance.ts b/src/api/instance.ts index 73975956..86d9a367 100644 --- a/src/api/instance.ts +++ b/src/api/instance.ts @@ -100,16 +100,7 @@ const apiInstance = async ({ }) }) .catch(error => { - // if (Math.random() < 0.001) { - // Sentry.Native.setExtras({ - // API: 'instance', - // ...(error.response && { response: error.response }), - // ...(error.request && { request: error.request }) - // }) - // Sentry.Native.captureException(error) - // } - - if (error.response) { + if (error?.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.error( @@ -122,7 +113,7 @@ const apiInstance = async ({ status: error.response.status, message: error.response.data.error }) - } else if (error.request) { + } else if (error?.request) { // The request was made but no response was received // `error.request` is an instance of XMLHttpRequest in the browser and an instance of // http.ClientRequest in node.js @@ -132,7 +123,7 @@ const apiInstance = async ({ console.error( ctx.bold(' API instance '), ctx.bold('internal'), - error.message, + error?.message, url ) return Promise.reject() diff --git a/src/api/tooot.ts b/src/api/tooot.ts index 6e7b9ba3..db5c86af 100644 --- a/src/api/tooot.ts +++ b/src/api/tooot.ts @@ -66,16 +66,16 @@ const apiTooot = async ({ }) }) .catch(error => { - if (sentry && Math.random() < 0.01) { + if (sentry && Math.random() < 0.1) { Sentry.Native.setExtras({ API: 'tooot', - ...(error.response && { response: error.response }), - ...(error.request && { request: error.request }) + ...(error?.response && { response: error.response }), + ...(error?.request && { request: error.request }) }) Sentry.Native.captureException(error) } - if (error.response) { + if (error?.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.error( @@ -88,7 +88,7 @@ const apiTooot = async ({ status: error.response.status, message: error.response.data.error }) - } else if (error.request) { + } else if (error?.request) { // The request was made but no response was received // `error.request` is an instance of XMLHttpRequest in the browser and an instance of // http.ClientRequest in node.js @@ -102,7 +102,7 @@ const apiTooot = async ({ console.error( ctx.bold(' API tooot '), ctx.bold('internal'), - error.message, + error?.message, url ) return Promise.reject() diff --git a/src/startup/netInfo.ts b/src/startup/netInfo.ts index 55a7fc68..21188668 100644 --- a/src/startup/netInfo.ts +++ b/src/startup/netInfo.ts @@ -41,10 +41,10 @@ const netInfo = async (): Promise<{ }).then(res => res.body) } catch (error: any) { log('error', 'netInfo', 'local credential check failed') - if (error.status && error.status == 401) { + if (error?.status && error.status == 401) { store.dispatch(removeInstance(instance)) } - return Promise.resolve({ corrupted: error.data.error }) + return Promise.resolve({ corrupted: error.data?.error }) } log('log', 'netInfo', 'local credential check passed') diff --git a/src/utils/push/useConnect.ts b/src/utils/push/useConnect.ts index 79f04f43..84174ea4 100644 --- a/src/utils/push/useConnect.ts +++ b/src/utils/push/useConnect.ts @@ -35,7 +35,7 @@ const pushUseConnect = ({ t, instances }: Params) => { url: `push/connect/${expoToken}`, sentry: true }).catch(error => { - if (error.status == 404) { + if (error?.status == 404) { displayMessage({ theme, type: 'error',