Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/notifications/AppExplorer/AppCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SpannerSVG from '@/assets/Spanner.svg'
import Badge from '@/components/general/Badge'
import Text from '@/components/general/Text'
import W3iContext from '@/contexts/W3iContext/context'
import { logError } from '@/utils/error'
import { getErrorMessage, logError } from '@/utils/error'
import { showErrorMessageToast, showSuccessMessageToast } from '@/utils/toasts'

import SubscribeButton from './SubscribeButton'
Expand Down Expand Up @@ -69,9 +69,10 @@ const AppCard: React.FC<AppCardProps> = ({
appDomain: new URL(url).host
})
} catch (error) {
const message = getErrorMessage(error, `Failed to subscribe to ${name}`)
logError(error)
setSubscribing(false)
showErrorMessageToast(`Failed to subscribe to ${name}`)
showErrorMessageToast(message)
}
},
[userPubkey, name, description, logo, url, setSubscribing, subscribed, notifyClientProxy]
Expand Down
22 changes: 21 additions & 1 deletion src/utils/error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { captureException } from '@sentry/react'

export const logError = (error: any) => {
const errorCodeMessageMap = {
socketStalled: 'Socket stalled when trying to connect to wss://relay.walletconnect.org'
}

export const getErrorMessage = (error: unknown, defaultMessage: string) => {
if (error?.message?.includes('timeout')) {
return 'Failed to subscribe, check your connection and try again'
}

switch (error?.message) {
case errorCodeMessageMap.socketStalled:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it stalls while updating

return 'Failed to subscribe, check your connection and try again'
default:
return defaultMessage || error?.message
}
}

export const logError = (error: unknown) => {
console.error(error)
if (error?.message === errorCodeMessageMap.socketStalled) {
return
}
captureException(error)
}