import axios, { AxiosError } from 'axios'; import PrettyJson from './Common/PrettyJSON'; export type ErrorInfo = string | Error | AxiosError | undefined; interface BackendErrorProps { error: ErrorInfo } function DescribeError(error: ErrorInfo) { if (!error) { return

Ошибки отсутствуют

; } else if (typeof error === 'string') { return

{error}

; } else if (axios.isAxiosError(error)) { if (!error?.response) { return

Нет ответа от сервера

; } if (error.response.status === 404) { return (

{`Обращение к несуществующему API`}

); } return (

Ошибка

{error.message}

{error.response.data && (<>

Описание

)}
); } else { return ; } } function BackendError({error}: BackendErrorProps) { return (
{DescribeError(error)}
); } export default BackendError;