25 lines
590 B
TypeScript
25 lines
590 B
TypeScript
import type * as t from '@/api/ius/types';
|
|
import { HttpError } from 'ui';
|
|
import type { WretchError } from 'wretch/types';
|
|
|
|
type Props = {
|
|
render: () => Promise<JSX.Element>;
|
|
};
|
|
|
|
export async function withError({ render }: Props) {
|
|
try {
|
|
return await render();
|
|
} catch (error) {
|
|
const _error = error as WretchError;
|
|
const json = _error.json as t.HttpError;
|
|
|
|
return (
|
|
<HttpError
|
|
code={_error.status.toString()}
|
|
title={json?.title || _error.name}
|
|
description={json?.errors?.join('') || _error.message || _error.text}
|
|
/>
|
|
);
|
|
}
|
|
}
|