Skip to content

Commit

Permalink
refactor: return-error-message helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepasha419a committed Aug 29, 2024
1 parent 378c2ac commit c086a66
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/shared/lib/helpers/returnErrorMessage.ts
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';
}

0 comments on commit c086a66

Please sign in to comment.