mirror of
https://github.com/tooot-app/app
synced 2025-04-23 22:57:23 +02: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 => {
|
.catch(error => {
|
||||||
// if (sentry && Math.random() < 0.01) {
|
if (error?.response) {
|
||||||
// Sentry.Native.setExtras({
|
|
||||||
// API: 'general',
|
|
||||||
// ...(error.response && { response: error.response }),
|
|
||||||
// ...(error.request && { request: error.request })
|
|
||||||
// })
|
|
||||||
// Sentry.Native.captureException(error)
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (error.response) {
|
|
||||||
// The request was made and the server responded with a status code
|
// The request was made and the server responded with a status code
|
||||||
// that falls out of the range of 2xx
|
// that falls out of the range of 2xx
|
||||||
console.error(
|
console.error(
|
||||||
@ -80,7 +71,7 @@ const apiGeneral = async <T = unknown>({
|
|||||||
status: error.response.status,
|
status: error.response.status,
|
||||||
message: error.response.data.error
|
message: error.response.data.error
|
||||||
})
|
})
|
||||||
} else if (error.request) {
|
} else if (error?.request) {
|
||||||
// The request was made but no response was received
|
// The request was made but no response was received
|
||||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
// http.ClientRequest in node.js
|
// http.ClientRequest in node.js
|
||||||
@ -94,7 +85,7 @@ const apiGeneral = async <T = unknown>({
|
|||||||
console.error(
|
console.error(
|
||||||
ctx.bold(' API general '),
|
ctx.bold(' API general '),
|
||||||
ctx.bold('internal'),
|
ctx.bold('internal'),
|
||||||
error.message,
|
error?.message,
|
||||||
url
|
url
|
||||||
)
|
)
|
||||||
return Promise.reject()
|
return Promise.reject()
|
||||||
|
@ -100,16 +100,7 @@ const apiInstance = async <T = unknown>({
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
// if (Math.random() < 0.001) {
|
if (error?.response) {
|
||||||
// Sentry.Native.setExtras({
|
|
||||||
// API: 'instance',
|
|
||||||
// ...(error.response && { response: error.response }),
|
|
||||||
// ...(error.request && { request: error.request })
|
|
||||||
// })
|
|
||||||
// Sentry.Native.captureException(error)
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (error.response) {
|
|
||||||
// The request was made and the server responded with a status code
|
// The request was made and the server responded with a status code
|
||||||
// that falls out of the range of 2xx
|
// that falls out of the range of 2xx
|
||||||
console.error(
|
console.error(
|
||||||
@ -122,7 +113,7 @@ const apiInstance = async <T = unknown>({
|
|||||||
status: error.response.status,
|
status: error.response.status,
|
||||||
message: error.response.data.error
|
message: error.response.data.error
|
||||||
})
|
})
|
||||||
} else if (error.request) {
|
} else if (error?.request) {
|
||||||
// The request was made but no response was received
|
// The request was made but no response was received
|
||||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
// http.ClientRequest in node.js
|
// http.ClientRequest in node.js
|
||||||
@ -132,7 +123,7 @@ const apiInstance = async <T = unknown>({
|
|||||||
console.error(
|
console.error(
|
||||||
ctx.bold(' API instance '),
|
ctx.bold(' API instance '),
|
||||||
ctx.bold('internal'),
|
ctx.bold('internal'),
|
||||||
error.message,
|
error?.message,
|
||||||
url
|
url
|
||||||
)
|
)
|
||||||
return Promise.reject()
|
return Promise.reject()
|
||||||
|
@ -66,16 +66,16 @@ const apiTooot = async <T = unknown>({
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (sentry && Math.random() < 0.01) {
|
if (sentry && Math.random() < 0.1) {
|
||||||
Sentry.Native.setExtras({
|
Sentry.Native.setExtras({
|
||||||
API: 'tooot',
|
API: 'tooot',
|
||||||
...(error.response && { response: error.response }),
|
...(error?.response && { response: error.response }),
|
||||||
...(error.request && { request: error.request })
|
...(error?.request && { request: error.request })
|
||||||
})
|
})
|
||||||
Sentry.Native.captureException(error)
|
Sentry.Native.captureException(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error.response) {
|
if (error?.response) {
|
||||||
// The request was made and the server responded with a status code
|
// The request was made and the server responded with a status code
|
||||||
// that falls out of the range of 2xx
|
// that falls out of the range of 2xx
|
||||||
console.error(
|
console.error(
|
||||||
@ -88,7 +88,7 @@ const apiTooot = async <T = unknown>({
|
|||||||
status: error.response.status,
|
status: error.response.status,
|
||||||
message: error.response.data.error
|
message: error.response.data.error
|
||||||
})
|
})
|
||||||
} else if (error.request) {
|
} else if (error?.request) {
|
||||||
// The request was made but no response was received
|
// The request was made but no response was received
|
||||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
// http.ClientRequest in node.js
|
// http.ClientRequest in node.js
|
||||||
@ -102,7 +102,7 @@ const apiTooot = async <T = unknown>({
|
|||||||
console.error(
|
console.error(
|
||||||
ctx.bold(' API tooot '),
|
ctx.bold(' API tooot '),
|
||||||
ctx.bold('internal'),
|
ctx.bold('internal'),
|
||||||
error.message,
|
error?.message,
|
||||||
url
|
url
|
||||||
)
|
)
|
||||||
return Promise.reject()
|
return Promise.reject()
|
||||||
|
@ -41,10 +41,10 @@ const netInfo = async (): Promise<{
|
|||||||
}).then(res => res.body)
|
}).then(res => res.body)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
log('error', 'netInfo', 'local credential check failed')
|
log('error', 'netInfo', 'local credential check failed')
|
||||||
if (error.status && error.status == 401) {
|
if (error?.status && error.status == 401) {
|
||||||
store.dispatch(removeInstance(instance))
|
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')
|
log('log', 'netInfo', 'local credential check passed')
|
||||||
|
@ -35,7 +35,7 @@ const pushUseConnect = ({ t, instances }: Params) => {
|
|||||||
url: `push/connect/${expoToken}`,
|
url: `push/connect/${expoToken}`,
|
||||||
sentry: true
|
sentry: true
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error.status == 404) {
|
if (error?.status == 404) {
|
||||||
displayMessage({
|
displayMessage({
|
||||||
theme,
|
theme,
|
||||||
type: 'error',
|
type: 'error',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user