import { faCircleExclamation } from "@fortawesome/free-solid-svg-icons"; import { FestaIcon } from "../renderers/fontawesome"; import { default as classNames } from "classnames" import style from "./renderers.module.css" import mood from "../../../styles/mood.module.css" import { ComponentPropsWithoutRef, memo } from "react"; import { AxiosError } from "axios"; import { ViewNotice } from "../views/notice"; /** * Props of {@link ErrorTrace}. */ type ErrorTraceProps = ComponentPropsWithoutRef<"code"> & { /** * The error to render the stack trace of. */ error: Error, /** * Whether error messages in JSON format should be prettified or not. */ prettify: boolean, } /** * Component rendering the details of an {@link Error}. * * Not to use by itself; should be used to display the error in other error renderers. */ const ErrorTrace = memo(({ error, prettify, ...props }: ErrorTraceProps) => { if (error instanceof AxiosError) { if (error.response) { if (error.response.data) { const json = JSON.stringify(error.response.data, undefined, prettify ? 4 : undefined).replaceAll("\\n", "\n") return ( API {error.response.status} {json} ) } return ( HTTP {error.response.status} {error.message} ) } return ( {error.code} {error.message} ) } return ( {error.name} {error.message} ) }) ErrorTrace.displayName = "ErrorTrace" /** * Props for "error" renderers. */ export type ErrorProps = { error: Error, text?: string } /** * Inline component for rendering errors. * * It displays an error {@link FestaIcon}, followed by some optional text, and finally the {@link ErrorTrace}. */ export const ErrorInline = memo(({ error, text }: ErrorProps) => { return ( {!!text && <>   {text}   } ) }) ErrorInline.displayName = "ErrorInline" /** * Block component for rendering errors. * * It displays an inline error {@link FestaIcon}, followed by some **required** text, with the {@link ErrorTrace} below. */ export const ErrorBlock = memo(({ error, text }: ErrorProps & { text: string }) => { return (

  {text}

                
            
) }) ErrorBlock.displayName = "ErrorBlock" /** * Block component for rendering errors at the center of the page. * * It displays an inline error {@link FestaIcon}, followed by some **required** text, with the {@link ErrorTrace} below. */ export const ErrorMain = memo(({ error, text }: ErrorProps) => { return (
{text &&

{text}

}
                
            
) }) ErrorMain.displayName = "ErrorMain" /** * {@link ViewNotice} component for rendering {@link ErrorMain}. */ export const ErrorView = memo((props: ErrorProps) => { return ( } /> ) }) ErrorView.displayName = "ErrorView"