Skip to content

Commit

Permalink
[PAY-3437] Add names to chats sentry reports (#10049)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan authored Oct 15, 2024
1 parent aad3c1d commit 7494a1a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 54 deletions.
18 changes: 8 additions & 10 deletions packages/common/src/hooks/chats/useSetInboxPermissions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from 'react'

import type { AudiusSdk } from '@audius/sdk'
import { useDispatch, useSelector } from 'react-redux'

import { useAudiusQueryContext } from '~/audius-query'
import { useAppContext } from '~/context/appContext'
import { Name } from '~/models/Analytics'
import { accountSelectors } from '~/store/account'
Expand All @@ -17,13 +17,8 @@ const { fetchPermissions } = chatActions
const { getChatPermissionsStatus, getUserChatPermissions } = chatSelectors
const { getUserId } = accountSelectors

type useSetInboxPermissionsProps = {
audiusSdk: () => Promise<AudiusSdk>
}

export const useSetInboxPermissions = ({
audiusSdk
}: useSetInboxPermissionsProps) => {
export const useSetInboxPermissions = () => {
const { audiusSdk, reportToSentry } = useAudiusQueryContext()
const dispatch = useDispatch()
const permissions = useSelector(getUserChatPermissions)
const {
Expand Down Expand Up @@ -53,7 +48,10 @@ export const useSetInboxPermissions = ({
})
)
} catch (e) {
console.error('Error saving chat permissions:', e)
reportToSentry({
name: 'Chats',
error: e as Error
})
track(
make({
eventName: Name.CHANGE_INBOX_SETTINGS_FAILURE,
Expand All @@ -62,7 +60,7 @@ export const useSetInboxPermissions = ({
)
}
},
[audiusSdk, track, make, doFetchPermissions]
[audiusSdk, doFetchPermissions, track, make, reportToSentry]
)

return {
Expand Down
54 changes: 18 additions & 36 deletions packages/common/src/store/pages/chat/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import { ulid } from 'ulid'

import { Name } from '~/models/Analytics'
import { ErrorLevel } from '~/models/ErrorReporting'
import { ID } from '~/models/Identifiers'
import { Status } from '~/models/Status'
import { getAccountUser, getUserId } from '~/store/account/selectors'
Expand Down Expand Up @@ -122,11 +121,10 @@ function* doFetchUnreadMessagesCount() {
fetchUnreadMessagesCountSucceeded({ unreadMessagesCount: response.data })
)
} catch (e) {
console.error('fetchUnreadMessagesCountFailed', e)
yield* put(fetchUnreadMessagesCountFailed())
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand Down Expand Up @@ -170,11 +168,10 @@ function* doFetchLatestChats() {
})
)
} catch (e) {
console.error('fetchLatestChatsFailed', e)
yield* put(fetchMoreChatsFailed())
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All @@ -198,11 +195,10 @@ function* doFetchMoreChats() {
yield* fetchUsersForChats(response.data)
yield* put(fetchMoreChatsSucceeded(response))
} catch (e) {
console.error('fetchMoreChatsFailed', e)
yield* put(fetchMoreChatsFailed())
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand Down Expand Up @@ -263,11 +259,10 @@ function* doFetchLatestMessages(
})
)
} catch (e) {
console.error('fetchLatestChatMessagesFailed', e)
yield* put(fetchMoreMessagesFailed({ chatId }))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand Down Expand Up @@ -325,11 +320,10 @@ function* doFetchMoreMessages(action: ReturnType<typeof fetchMoreMessages>) {
})
)
} catch (e) {
console.error('fetchMoreChatMessagesFailed', e)
yield* put(fetchMoreMessagesFailed({ chatId }))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand Down Expand Up @@ -373,11 +367,10 @@ function* doSetMessageReaction(action: ReturnType<typeof setMessageReaction>) {
})
)
} catch (e) {
console.error('setMessageReactionFailed', e)
yield* put(setMessageReactionFailed(action.payload))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId,
Expand Down Expand Up @@ -435,7 +428,6 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {
yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS }))
}
} catch (e) {
console.error('createChatFailed', e)
yield* put(
toast({
type: 'error',
Expand All @@ -444,7 +436,7 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {
)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
userIds
Expand Down Expand Up @@ -512,7 +504,6 @@ function* doCreateChatBlast(action: ReturnType<typeof createChatBlast>) {
)
}
} catch (e) {
console.error('createChatBlastFailed', e)
yield* put(
toast({
type: 'error',
Expand All @@ -521,7 +512,7 @@ function* doCreateChatBlast(action: ReturnType<typeof createChatBlast>) {
)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
audience,
Expand Down Expand Up @@ -567,11 +558,10 @@ function* doMarkChatAsRead(action: ReturnType<typeof markChatAsRead>) {
yield* put(markChatAsReadFailed({ chatId }))
}
} catch (e) {
console.error('markChatAsReadFailed', e)
yield* put(markChatAsReadFailed({ chatId }))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand Down Expand Up @@ -637,7 +627,6 @@ function* doSendMessage(action: ReturnType<typeof sendMessage>) {
}
yield* call(track, make({ eventName: Name.SEND_MESSAGE_SUCCESS }))
} catch (e) {
console.error('sendMessageFailed', e)
yield* put(sendMessageFailed({ chatId, messageId: messageIdToUse }))

// Fetch the chat to see if permissions need rechecking
Expand All @@ -658,7 +647,7 @@ function* doSendMessage(action: ReturnType<typeof sendMessage>) {
}
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId,
Expand Down Expand Up @@ -700,10 +689,9 @@ function* doFetchBlockees() {
})
)
} catch (e) {
console.error('fetchBlockeesFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All @@ -722,10 +710,9 @@ function* doFetchBlockers() {
})
)
} catch (e) {
console.error('fetchBlockersFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All @@ -746,10 +733,9 @@ function* doBlockUser(action: ReturnType<typeof blockUser>) {
make({ eventName: Name.BLOCK_USER_SUCCESS, blockedUserId: userId })
)
} catch (e) {
console.error('blockUserFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
yield* call(
Expand All @@ -768,10 +754,9 @@ function* doUnblockUser(action: ReturnType<typeof unblockUser>) {
})
yield* put(fetchBlockees())
} catch (e) {
console.error('unblockUserFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand Down Expand Up @@ -800,10 +785,9 @@ function* doFetchPermissions(action: ReturnType<typeof fetchPermissions>) {
})
)
} catch (e) {
console.error('fetchPermissionsFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All @@ -829,10 +813,9 @@ function* doFetchLinkUnfurlMetadata(
fetchLinkUnfurlSucceeded({ chatId, messageId, unfurlMetadata: data[0] })
)
} catch (e) {
console.error('fetchUnfurlFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId,
Expand Down Expand Up @@ -860,10 +843,9 @@ function* doDeleteChat(action: ReturnType<typeof deleteChat>) {
yield* put(deleteChatSucceeded({ chatId }))
yield* call(track, make({ eventName: Name.DELETE_CHAT_SUCCESS }))
} catch (e) {
console.error('deleteChat failed', e, { chatId })
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand All @@ -878,7 +860,7 @@ function* doLogError({ payload: { error } }: ReturnType<typeof logError>) {
const reportToSentry = yield* getContext('reportToSentry')
const { code, url } = error
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error,
additionalInfo: {
code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Formik } from 'formik'

import { Button, Flex, IconMessage } from '@audius/harmony-native'
import { HeaderShadow, ScreenContent } from 'app/components/core'
import { audiusSdk } from 'app/services/sdk/audius-sdk'

import { FormScreen } from '../form-screen'

Expand All @@ -21,9 +20,7 @@ const messages = {

export const InboxSettingsScreenNew = () => {
const { permissions, doFetchPermissions, savePermissions } =
useSetInboxPermissions({
audiusSdk
})
useSetInboxPermissions()

const initialValues = useMemo(() => {
return transformPermitListToMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { ChatPermission } from '@audius/sdk'
import { Formik, useField, useFormikContext } from 'formik'

import { useModalState } from 'common/hooks/useModalState'
import { audiusSdk } from 'services/audius-sdk'

const messages = {
title: 'Inbox Settings',
Expand Down Expand Up @@ -84,9 +83,7 @@ export const InboxSettingsModalNew = () => {
doFetchPermissions,
permissionsStatus,
savePermissions
} = useSetInboxPermissions({
audiusSdk
})
} = useSetInboxPermissions()

const handleSave = useCallback(
(values: InboxSettingsFormValues) => {
Expand Down

0 comments on commit 7494a1a

Please sign in to comment.