mirror of
https://github.com/tooot-app/app
synced 2025-03-14 02:20:13 +01:00
Refine logging
This commit is contained in:
parent
8d0a58b975
commit
79246ff821
@ -1,6 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import handleError, { ctx } from './handleError'
|
||||
import { userAgent } from './helpers'
|
||||
import { ctx, handleError, userAgent } from './helpers'
|
||||
|
||||
export type Params = {
|
||||
method: 'get' | 'post' | 'put' | 'delete'
|
||||
|
@ -1,31 +0,0 @@
|
||||
import chalk from 'chalk'
|
||||
|
||||
export const ctx = new chalk.Instance({ level: 3 })
|
||||
|
||||
const handleError = (error: any) => {
|
||||
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(
|
||||
ctx.bold(' API '),
|
||||
ctx.bold('response'),
|
||||
error.response.status,
|
||||
error?.response.data?.error || error?.response.message || 'Unknown error'
|
||||
)
|
||||
return Promise.reject({
|
||||
status: error?.response.status,
|
||||
message: error?.response.data?.error || error?.response.message || 'Unknown error'
|
||||
})
|
||||
} 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
|
||||
console.error(ctx.bold(' API '), ctx.bold('request'), error)
|
||||
return Promise.reject()
|
||||
} else {
|
||||
console.error(ctx.bold(' API '), ctx.bold('internal'), error?.message)
|
||||
return Promise.reject()
|
||||
}
|
||||
}
|
||||
|
||||
export default handleError
|
@ -1,6 +1,36 @@
|
||||
import Constants from "expo-constants"
|
||||
import { Platform } from "react-native"
|
||||
import chalk from 'chalk'
|
||||
import Constants from 'expo-constants'
|
||||
import { Platform } from 'react-native'
|
||||
|
||||
const userAgent = { 'User-Agent': `tooot/${Constants.expoConfig?.version} ${Platform.OS}/${Platform.Version}` }
|
||||
const userAgent = {
|
||||
'User-Agent': `tooot/${Constants.expoConfig?.version} ${Platform.OS}/${Platform.Version}`
|
||||
}
|
||||
|
||||
export { userAgent }
|
||||
const ctx = new chalk.Instance({ level: 3 })
|
||||
const handleError = (error: any) => {
|
||||
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(
|
||||
ctx.bold(' API '),
|
||||
ctx.bold('response'),
|
||||
error.response.status,
|
||||
error?.response.data?.error || error?.response.message || 'Unknown error'
|
||||
)
|
||||
return Promise.reject({
|
||||
status: error?.response.status,
|
||||
message: error?.response.data?.error || error?.response.message || 'Unknown error'
|
||||
})
|
||||
} 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
|
||||
console.error(ctx.bold(' API '), ctx.bold('request'), error)
|
||||
return Promise.reject()
|
||||
} else {
|
||||
console.error(ctx.bold(' API '), ctx.bold('internal'), error?.message)
|
||||
return Promise.reject()
|
||||
}
|
||||
}
|
||||
|
||||
export { ctx, handleError, userAgent }
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { RootState } from '@root/store'
|
||||
import axios, { AxiosRequestConfig } from 'axios'
|
||||
import li from 'li'
|
||||
import handleError, { ctx } from './handleError'
|
||||
import { userAgent } from './helpers'
|
||||
import { ctx, handleError, userAgent } from './helpers'
|
||||
|
||||
export type Params = {
|
||||
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
|
||||
|
@ -1,8 +1,7 @@
|
||||
import * as Sentry from '@sentry/react-native'
|
||||
import { mapEnvironment } from '@utils/checkEnvironment'
|
||||
import axios from 'axios'
|
||||
import handleError, { ctx } from './handleError'
|
||||
import { userAgent } from './helpers'
|
||||
import { ctx, handleError, userAgent } from './helpers'
|
||||
|
||||
export type Params = {
|
||||
method: 'get' | 'post' | 'put' | 'delete'
|
||||
@ -57,14 +56,12 @@ const apiTooot = async <T = unknown>({
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
Sentry.setExtras({
|
||||
API: 'tooot',
|
||||
request: { url, params, body },
|
||||
...(error?.response && { response: error.response })
|
||||
})
|
||||
Sentry.captureMessage('API error', {
|
||||
contexts: { errorObject: error }
|
||||
Sentry.setContext('API request', { url, params, body })
|
||||
Sentry.setContext('Error response', {
|
||||
...(error?.response && { response: error.response?._response })
|
||||
})
|
||||
Sentry.setContext('Error object', { error })
|
||||
Sentry.captureMessage('API error')
|
||||
|
||||
return handleError(error)
|
||||
})
|
||||
|
@ -319,9 +319,8 @@ const ScreenCompose: React.FC<RootStackScreenProps<'Screen-Compose'>> = ({
|
||||
]
|
||||
)
|
||||
} else {
|
||||
Sentry.captureMessage('Compose posting', {
|
||||
contexts: { errorObject: error }
|
||||
})
|
||||
Sentry.setContext('Error object', { error })
|
||||
Sentry.captureMessage('Posting error')
|
||||
haptics('Error')
|
||||
composeDispatch({ type: 'posting', payload: false })
|
||||
Alert.alert(t('heading.right.alert.default.title'), undefined, [
|
||||
|
@ -33,14 +33,11 @@ const pushUseConnect = () => {
|
||||
})
|
||||
.then(() => Notifications.setBadgeCountAsync(0))
|
||||
.catch(error => {
|
||||
Sentry.setExtras({
|
||||
API: 'tooot',
|
||||
expoToken,
|
||||
...(error?.response && { response: error.response })
|
||||
})
|
||||
Sentry.captureMessage('Push connect error', {
|
||||
contexts: { errorObject: error }
|
||||
Sentry.setContext('Error response', {
|
||||
...(error?.response && { response: error.response?._response })
|
||||
})
|
||||
Sentry.setContext('Error object', { error })
|
||||
Sentry.captureMessage('Push connect error')
|
||||
Notifications.setBadgeCountAsync(0)
|
||||
if (error?.status == 404) {
|
||||
displayMessage({
|
||||
@ -84,10 +81,7 @@ const pushUseConnect = () => {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
Sentry.setExtras({
|
||||
expoToken,
|
||||
pushEnabledCount: pushEnabled
|
||||
})
|
||||
Sentry.setContext('Push', { expoToken, pushEnabledCount: pushEnabled.length })
|
||||
|
||||
if (expoToken && pushEnabled.length) {
|
||||
connect()
|
||||
|
@ -74,8 +74,7 @@ const pushRegister = async (
|
||||
})
|
||||
|
||||
if (!res.body.server_key?.length) {
|
||||
Sentry.setExtras({
|
||||
API: 'tooot',
|
||||
Sentry.setContext('Push server key', {
|
||||
instance: instanceUri,
|
||||
resBody: res.body
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user