File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { AxiosError } from "axios"
12import type { ApiError } from "./client"
2- import useCustomToast from "./hooks/useCustomToast"
33
4- export const handleError = ( err : ApiError ) => {
5- const { showErrorToast } = useCustomToast ( )
4+ function extractErrorMessage ( err : ApiError ) : string {
5+ if ( err instanceof AxiosError ) {
6+ return err . message
7+ }
8+
69 const errDetail = ( err . body as any ) ?. detail
7- let errorMessage = errDetail || "Something went wrong."
810 if ( Array . isArray ( errDetail ) && errDetail . length > 0 ) {
9- errorMessage = errDetail [ 0 ] . msg
11+ return errDetail [ 0 ] . msg
1012 }
11- showErrorToast ( errorMessage )
13+ return errDetail || "Something went wrong."
14+ }
15+
16+ export const handleError = function ( this : ( msg : string ) => void , err : ApiError ) {
17+ const errorMessage = extractErrorMessage ( err )
18+ this ( errorMessage )
1219}
You can’t perform that action at this time.
0 commit comments