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) { console.log(error); if (!error) { return

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

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

{error}

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

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

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

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

); } const isHtml = error.response.headers['content-type'].includes('text/html'); return (

Ошибка

{error.message}

{error.response.data && (<>

Описание

{ isHtml &&
} { !isHtml && } )}
); } function BackendError({error}: BackendErrorProps) { return (
{DescribeError(error)}
); } export default BackendError;