Skip to content

Commit

Permalink
Merge pull request #705 from dappforce/fix/cache
Browse files Browse the repository at this point in the history
Show error message in error toast
  • Loading branch information
teodorus-nathaniel authored Sep 13, 2024
2 parents 28ea9ed + 0f50079 commit 07115e9
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/hooks/useToastError.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CustomToast from '@/components/Toast'
import truncate from 'lodash.truncate'
import { ReactNode, useEffect, useRef } from 'react'
import { toast, Toast, ToastOptions } from 'react-hot-toast'
import { Toast, ToastOptions, toast } from 'react-hot-toast'

export function showErrorToast<ErrorType>(
error: unknown,
Expand All @@ -13,23 +14,26 @@ export function showErrorToast<ErrorType>(
}
) {
const { actionButton, getMessage, toastConfig } = config ?? {}
// TODO: this error message should be sent to logger for debugging purposes, but not shown to user
// let message: string | undefined = (error as any)?.message
let message: string | undefined = (error as any)?.message

// const response = (error as any)?.response?.data
// message = response?.message ?? message
// if (getMessage) {
// const responseMessage = getMessage(response)
// if (responseMessage) message = responseMessage
// }
const response = (error as any)?.response?.data
message = response?.message ?? message
if (getMessage) {
const responseMessage = getMessage(response)
if (responseMessage) message = responseMessage
}

message = truncate(typeof message === 'string' ? message : '', {
length: 150,
})

toast.custom(
(t) => (
<CustomToast
t={t}
type='error'
title={errorTitle}
// subtitle={message}
subtitle={message}
description={config?.getDescription?.(t)}
action={actionButton?.(t)}
/>
Expand Down

0 comments on commit 07115e9

Please sign in to comment.