-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: return-error-message helper
- Loading branch information
1 parent
378c2ac
commit c086a66
Showing
1 changed file
with
8 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import type { AxiosError } from 'axios'; | ||
import axios from 'axios'; | ||
|
||
export type AxiosErrorResponse = AxiosError<{ | ||
message: string; | ||
statusCode: number; | ||
}>; | ||
|
||
export function returnErrorMessage(error: unknown) { | ||
return axios.isAxiosError(error) | ||
? (error as AxiosErrorResponse).response!.data.message | ||
: (error as Error).message; | ||
export function returnErrorMessage(error: unknown): string { | ||
if (error instanceof Error || axios.isAxiosError(error)) { | ||
return error.message; | ||
} | ||
if (typeof error === 'string') { | ||
return error; | ||
} | ||
return 'undefined error'; | ||
} |