mirror of
https://github.com/tooot-app/app
synced 2025-01-06 23:01:51 +01:00
Make error object as optional
This commit is contained in:
parent
4b3b222582
commit
02360c443f
@ -58,16 +58,7 @@ const apiGeneral = async <T = unknown>({
|
||||
})
|
||||
})
|
||||
.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 <T = unknown>({
|
||||
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 <T = unknown>({
|
||||
console.error(
|
||||
ctx.bold(' API general '),
|
||||
ctx.bold('internal'),
|
||||
error.message,
|
||||
error?.message,
|
||||
url
|
||||
)
|
||||
return Promise.reject()
|
||||
|
@ -100,16 +100,7 @@ const apiInstance = async <T = unknown>({
|
||||
})
|
||||
})
|
||||
.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 <T = unknown>({
|
||||
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 <T = unknown>({
|
||||
console.error(
|
||||
ctx.bold(' API instance '),
|
||||
ctx.bold('internal'),
|
||||
error.message,
|
||||
error?.message,
|
||||
url
|
||||
)
|
||||
return Promise.reject()
|
||||
|
@ -66,16 +66,16 @@ const apiTooot = async <T = unknown>({
|
||||
})
|
||||
})
|
||||
.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 <T = unknown>({
|
||||
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 <T = unknown>({
|
||||
console.error(
|
||||
ctx.bold(' API tooot '),
|
||||
ctx.bold('internal'),
|
||||
error.message,
|
||||
error?.message,
|
||||
url
|
||||
)
|
||||
return Promise.reject()
|
||||
|
@ -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')
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user