2022-06-11 03:08:49 +00:00
|
|
|
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 { memo } from "react";
|
|
|
|
import { AxiosError } from "axios";
|
|
|
|
|
|
|
|
|
|
|
|
export type ErrorTraceProps = {
|
|
|
|
error: Error,
|
|
|
|
inline: boolean,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const ErrorTrace = memo((props: ErrorTraceProps) => {
|
|
|
|
if (props.error instanceof AxiosError) {
|
|
|
|
if (props.error.response) {
|
|
|
|
if (props.error.response.data) {
|
|
|
|
const json = JSON.stringify(props.error.response.data, undefined, props.inline ? undefined : 4).replaceAll("\\n", "\n")
|
|
|
|
|
|
|
|
return (
|
|
|
|
<code>
|
|
|
|
<b>API {props.error.response.status}</b>
|
|
|
|
:
|
|
|
|
{json}
|
|
|
|
</code>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<code>
|
|
|
|
<b>HTTP {props.error.response.status}</b>
|
|
|
|
:
|
|
|
|
{props.error.message}
|
|
|
|
</code>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<code>
|
|
|
|
<b>{props.error.code}</b>
|
|
|
|
:
|
|
|
|
{props.error.message}
|
|
|
|
</code>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<code>
|
|
|
|
<b>{props.error.name}</b>
|
|
|
|
:
|
|
|
|
{props.error.message}
|
|
|
|
</code>
|
|
|
|
)
|
|
|
|
})
|
2022-07-16 14:14:48 +00:00
|
|
|
ErrorTrace.displayName = "ErrorTrace"
|
2022-06-11 03:08:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
export type ErrorInlineProps = {
|
|
|
|
error: Error,
|
|
|
|
text?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component rendering a `span` element containing an error passed to it as props.
|
|
|
|
*
|
|
|
|
* May or may not include some text to display to the user.
|
|
|
|
*/
|
|
|
|
export const ErrorInline = memo((props: ErrorInlineProps) => {
|
|
|
|
return (
|
|
|
|
<span className={classNames("negative", style.error, style.errorInline)}>
|
|
|
|
<FestaIcon icon={faCircleExclamation} />
|
|
|
|
|
|
|
|
{props.text ?
|
|
|
|
<>
|
|
|
|
<span>
|
|
|
|
{props.text}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
</>
|
|
|
|
: null}
|
|
|
|
<ErrorTrace error={props.error} inline={true} />
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
})
|
2022-07-16 14:12:29 +00:00
|
|
|
ErrorInline.displayName = "ErrorInline"
|
2022-06-11 03:08:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
export type ErrorBlockProps = {
|
|
|
|
error: Error,
|
|
|
|
text: string
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component rendering a `div` element containing an error passed to it as props.
|
|
|
|
*
|
|
|
|
* Must include some text to display to the user.
|
|
|
|
*/
|
|
|
|
export const ErrorBlock = memo((props: ErrorBlockProps) => {
|
|
|
|
return (
|
|
|
|
<div className={classNames("negative", style.error, style.errorBlock)}>
|
|
|
|
<p>
|
|
|
|
<FestaIcon icon={faCircleExclamation} />
|
|
|
|
|
|
|
|
<span>
|
|
|
|
{props.text}
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
<pre>
|
|
|
|
<ErrorTrace error={props.error} inline={false} />
|
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})
|
2022-07-16 14:12:29 +00:00
|
|
|
ErrorBlock.displayName = "ErrorBlock"
|