Skip to content

Commit 7494a1a

Browse files
authored
[PAY-3437] Add names to chats sentry reports (#10049)
1 parent aad3c1d commit 7494a1a

File tree

4 files changed

+28
-54
lines changed

4 files changed

+28
-54
lines changed

packages/common/src/hooks/chats/useSetInboxPermissions.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useCallback } from 'react'
22

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

5+
import { useAudiusQueryContext } from '~/audius-query'
66
import { useAppContext } from '~/context/appContext'
77
import { Name } from '~/models/Analytics'
88
import { accountSelectors } from '~/store/account'
@@ -17,13 +17,8 @@ const { fetchPermissions } = chatActions
1717
const { getChatPermissionsStatus, getUserChatPermissions } = chatSelectors
1818
const { getUserId } = accountSelectors
1919

20-
type useSetInboxPermissionsProps = {
21-
audiusSdk: () => Promise<AudiusSdk>
22-
}
23-
24-
export const useSetInboxPermissions = ({
25-
audiusSdk
26-
}: useSetInboxPermissionsProps) => {
20+
export const useSetInboxPermissions = () => {
21+
const { audiusSdk, reportToSentry } = useAudiusQueryContext()
2722
const dispatch = useDispatch()
2823
const permissions = useSelector(getUserChatPermissions)
2924
const {
@@ -53,7 +48,10 @@ export const useSetInboxPermissions = ({
5348
})
5449
)
5550
} catch (e) {
56-
console.error('Error saving chat permissions:', e)
51+
reportToSentry({
52+
name: 'Chats',
53+
error: e as Error
54+
})
5755
track(
5856
make({
5957
eventName: Name.CHANGE_INBOX_SETTINGS_FAILURE,
@@ -62,7 +60,7 @@ export const useSetInboxPermissions = ({
6260
)
6361
}
6462
},
65-
[audiusSdk, track, make, doFetchPermissions]
63+
[audiusSdk, doFetchPermissions, track, make, reportToSentry]
6664
)
6765

6866
return {

packages/common/src/store/pages/chat/sagas.ts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
import { ulid } from 'ulid'
1818

1919
import { Name } from '~/models/Analytics'
20-
import { ErrorLevel } from '~/models/ErrorReporting'
2120
import { ID } from '~/models/Identifiers'
2221
import { Status } from '~/models/Status'
2322
import { getAccountUser, getUserId } from '~/store/account/selectors'
@@ -122,11 +121,10 @@ function* doFetchUnreadMessagesCount() {
122121
fetchUnreadMessagesCountSucceeded({ unreadMessagesCount: response.data })
123122
)
124123
} catch (e) {
125-
console.error('fetchUnreadMessagesCountFailed', e)
126124
yield* put(fetchUnreadMessagesCountFailed())
127125
const reportToSentry = yield* getContext('reportToSentry')
128126
reportToSentry({
129-
level: ErrorLevel.Error,
127+
name: 'Chats',
130128
error: e as Error
131129
})
132130
}
@@ -170,11 +168,10 @@ function* doFetchLatestChats() {
170168
})
171169
)
172170
} catch (e) {
173-
console.error('fetchLatestChatsFailed', e)
174171
yield* put(fetchMoreChatsFailed())
175172
const reportToSentry = yield* getContext('reportToSentry')
176173
reportToSentry({
177-
level: ErrorLevel.Error,
174+
name: 'Chats',
178175
error: e as Error
179176
})
180177
}
@@ -198,11 +195,10 @@ function* doFetchMoreChats() {
198195
yield* fetchUsersForChats(response.data)
199196
yield* put(fetchMoreChatsSucceeded(response))
200197
} catch (e) {
201-
console.error('fetchMoreChatsFailed', e)
202198
yield* put(fetchMoreChatsFailed())
203199
const reportToSentry = yield* getContext('reportToSentry')
204200
reportToSentry({
205-
level: ErrorLevel.Error,
201+
name: 'Chats',
206202
error: e as Error
207203
})
208204
}
@@ -263,11 +259,10 @@ function* doFetchLatestMessages(
263259
})
264260
)
265261
} catch (e) {
266-
console.error('fetchLatestChatMessagesFailed', e)
267262
yield* put(fetchMoreMessagesFailed({ chatId }))
268263
const reportToSentry = yield* getContext('reportToSentry')
269264
reportToSentry({
270-
level: ErrorLevel.Error,
265+
name: 'Chats',
271266
error: e as Error,
272267
additionalInfo: {
273268
chatId
@@ -325,11 +320,10 @@ function* doFetchMoreMessages(action: ReturnType<typeof fetchMoreMessages>) {
325320
})
326321
)
327322
} catch (e) {
328-
console.error('fetchMoreChatMessagesFailed', e)
329323
yield* put(fetchMoreMessagesFailed({ chatId }))
330324
const reportToSentry = yield* getContext('reportToSentry')
331325
reportToSentry({
332-
level: ErrorLevel.Error,
326+
name: 'Chats',
333327
error: e as Error,
334328
additionalInfo: {
335329
chatId
@@ -373,11 +367,10 @@ function* doSetMessageReaction(action: ReturnType<typeof setMessageReaction>) {
373367
})
374368
)
375369
} catch (e) {
376-
console.error('setMessageReactionFailed', e)
377370
yield* put(setMessageReactionFailed(action.payload))
378371
const reportToSentry = yield* getContext('reportToSentry')
379372
reportToSentry({
380-
level: ErrorLevel.Error,
373+
name: 'Chats',
381374
error: e as Error,
382375
additionalInfo: {
383376
chatId,
@@ -435,7 +428,6 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {
435428
yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS }))
436429
}
437430
} catch (e) {
438-
console.error('createChatFailed', e)
439431
yield* put(
440432
toast({
441433
type: 'error',
@@ -444,7 +436,7 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {
444436
)
445437
const reportToSentry = yield* getContext('reportToSentry')
446438
reportToSentry({
447-
level: ErrorLevel.Error,
439+
name: 'Chats',
448440
error: e as Error,
449441
additionalInfo: {
450442
userIds
@@ -512,7 +504,6 @@ function* doCreateChatBlast(action: ReturnType<typeof createChatBlast>) {
512504
)
513505
}
514506
} catch (e) {
515-
console.error('createChatBlastFailed', e)
516507
yield* put(
517508
toast({
518509
type: 'error',
@@ -521,7 +512,7 @@ function* doCreateChatBlast(action: ReturnType<typeof createChatBlast>) {
521512
)
522513
const reportToSentry = yield* getContext('reportToSentry')
523514
reportToSentry({
524-
level: ErrorLevel.Error,
515+
name: 'Chats',
525516
error: e as Error,
526517
additionalInfo: {
527518
audience,
@@ -567,11 +558,10 @@ function* doMarkChatAsRead(action: ReturnType<typeof markChatAsRead>) {
567558
yield* put(markChatAsReadFailed({ chatId }))
568559
}
569560
} catch (e) {
570-
console.error('markChatAsReadFailed', e)
571561
yield* put(markChatAsReadFailed({ chatId }))
572562
const reportToSentry = yield* getContext('reportToSentry')
573563
reportToSentry({
574-
level: ErrorLevel.Error,
564+
name: 'Chats',
575565
error: e as Error,
576566
additionalInfo: {
577567
chatId
@@ -637,7 +627,6 @@ function* doSendMessage(action: ReturnType<typeof sendMessage>) {
637627
}
638628
yield* call(track, make({ eventName: Name.SEND_MESSAGE_SUCCESS }))
639629
} catch (e) {
640-
console.error('sendMessageFailed', e)
641630
yield* put(sendMessageFailed({ chatId, messageId: messageIdToUse }))
642631

643632
// Fetch the chat to see if permissions need rechecking
@@ -658,7 +647,7 @@ function* doSendMessage(action: ReturnType<typeof sendMessage>) {
658647
}
659648
const reportToSentry = yield* getContext('reportToSentry')
660649
reportToSentry({
661-
level: ErrorLevel.Error,
650+
name: 'Chats',
662651
error: e as Error,
663652
additionalInfo: {
664653
chatId,
@@ -700,10 +689,9 @@ function* doFetchBlockees() {
700689
})
701690
)
702691
} catch (e) {
703-
console.error('fetchBlockeesFailed', e)
704692
const reportToSentry = yield* getContext('reportToSentry')
705693
reportToSentry({
706-
level: ErrorLevel.Error,
694+
name: 'Chats',
707695
error: e as Error
708696
})
709697
}
@@ -722,10 +710,9 @@ function* doFetchBlockers() {
722710
})
723711
)
724712
} catch (e) {
725-
console.error('fetchBlockersFailed', e)
726713
const reportToSentry = yield* getContext('reportToSentry')
727714
reportToSentry({
728-
level: ErrorLevel.Error,
715+
name: 'Chats',
729716
error: e as Error
730717
})
731718
}
@@ -746,10 +733,9 @@ function* doBlockUser(action: ReturnType<typeof blockUser>) {
746733
make({ eventName: Name.BLOCK_USER_SUCCESS, blockedUserId: userId })
747734
)
748735
} catch (e) {
749-
console.error('blockUserFailed', e)
750736
const reportToSentry = yield* getContext('reportToSentry')
751737
reportToSentry({
752-
level: ErrorLevel.Error,
738+
name: 'Chats',
753739
error: e as Error
754740
})
755741
yield* call(
@@ -768,10 +754,9 @@ function* doUnblockUser(action: ReturnType<typeof unblockUser>) {
768754
})
769755
yield* put(fetchBlockees())
770756
} catch (e) {
771-
console.error('unblockUserFailed', e)
772757
const reportToSentry = yield* getContext('reportToSentry')
773758
reportToSentry({
774-
level: ErrorLevel.Error,
759+
name: 'Chats',
775760
error: e as Error
776761
})
777762
}
@@ -800,10 +785,9 @@ function* doFetchPermissions(action: ReturnType<typeof fetchPermissions>) {
800785
})
801786
)
802787
} catch (e) {
803-
console.error('fetchPermissionsFailed', e)
804788
const reportToSentry = yield* getContext('reportToSentry')
805789
reportToSentry({
806-
level: ErrorLevel.Error,
790+
name: 'Chats',
807791
error: e as Error
808792
})
809793
}
@@ -829,10 +813,9 @@ function* doFetchLinkUnfurlMetadata(
829813
fetchLinkUnfurlSucceeded({ chatId, messageId, unfurlMetadata: data[0] })
830814
)
831815
} catch (e) {
832-
console.error('fetchUnfurlFailed', e)
833816
const reportToSentry = yield* getContext('reportToSentry')
834817
reportToSentry({
835-
level: ErrorLevel.Error,
818+
name: 'Chats',
836819
error: e as Error,
837820
additionalInfo: {
838821
chatId,
@@ -860,10 +843,9 @@ function* doDeleteChat(action: ReturnType<typeof deleteChat>) {
860843
yield* put(deleteChatSucceeded({ chatId }))
861844
yield* call(track, make({ eventName: Name.DELETE_CHAT_SUCCESS }))
862845
} catch (e) {
863-
console.error('deleteChat failed', e, { chatId })
864846
const reportToSentry = yield* getContext('reportToSentry')
865847
reportToSentry({
866-
level: ErrorLevel.Error,
848+
name: 'Chats',
867849
error: e as Error,
868850
additionalInfo: {
869851
chatId
@@ -878,7 +860,7 @@ function* doLogError({ payload: { error } }: ReturnType<typeof logError>) {
878860
const reportToSentry = yield* getContext('reportToSentry')
879861
const { code, url } = error
880862
reportToSentry({
881-
level: ErrorLevel.Error,
863+
name: 'Chats',
882864
error,
883865
additionalInfo: {
884866
code,

packages/mobile/src/screens/settings-screen/InboxSettingsScreenNew.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Formik } from 'formik'
88

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

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

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

2221
export const InboxSettingsScreenNew = () => {
2322
const { permissions, doFetchPermissions, savePermissions } =
24-
useSetInboxPermissions({
25-
audiusSdk
26-
})
23+
useSetInboxPermissions()
2724

2825
const initialValues = useMemo(() => {
2926
return transformPermitListToMap(

packages/web/src/components/inbox-settings-modal/InboxSettingsModalNew.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { ChatPermission } from '@audius/sdk'
2222
import { Formik, useField, useFormikContext } from 'formik'
2323

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

2726
const messages = {
2827
title: 'Inbox Settings',
@@ -84,9 +83,7 @@ export const InboxSettingsModalNew = () => {
8483
doFetchPermissions,
8584
permissionsStatus,
8685
savePermissions
87-
} = useSetInboxPermissions({
88-
audiusSdk
89-
})
86+
} = useSetInboxPermissions()
9087

9188
const handleSave = useCallback(
9289
(values: InboxSettingsFormValues) => {

0 commit comments

Comments
 (0)