import axios, { type AxiosError } from 'axios'; import { isResponseHtml } from '@/utils/utils'; import AnimateFade from './AnimateFade'; import PrettyJson from './ui/PrettyJSON'; export type ErrorData = string | Error | AxiosError | undefined; interface InfoErrorProps { error: ErrorData; } function DescribeError({ error }: { error: ErrorData }) { 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'}

); } // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call const isHtml = isResponseHtml(error.response); return (

Ошибка

{error.message}

{error.response.data && ( <>

Описание

{isHtml ?
: null} {!isHtml ? : null} )}
); } function InfoError({ error }: InfoErrorProps) { return ( ); } export default InfoError;