9 lines
414 B
TypeScript
9 lines
414 B
TypeScript
export function getErrorMessage(error: unknown, fallback = 'Произошла ошибка'): string {
|
|
if (error && typeof error === 'object' && 'response' in error) {
|
|
const axiosErr = error as { response?: { data?: { error?: string } } }
|
|
if (axiosErr.response?.data?.error) return axiosErr.response.data.error
|
|
}
|
|
if (error instanceof Error && error.message) return error.message
|
|
return fallback
|
|
}
|