apps/web: add http error to ius page
This commit is contained in:
parent
eeee8f8c0a
commit
859cf7b2b9
@ -14,3 +14,9 @@ export type ResponseGetData = Record<string, any>;
|
||||
export type ResponseMetaData = Record<string, MetaObject>;
|
||||
export type ResponseConfig = { title: string };
|
||||
export type ResponseConditions = string;
|
||||
|
||||
export type HttpError = {
|
||||
errors: string[];
|
||||
status: number;
|
||||
title: string;
|
||||
};
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import * as apiIUS from '@/api/ius/query';
|
||||
import type * as t from '@/api/ius/types';
|
||||
import * as Form from '@/components/Form';
|
||||
import type { PageProps } from '@/types/page';
|
||||
import { makeCreateUrl } from '@/utils/url';
|
||||
import type { Metadata } from 'next';
|
||||
import { Background, Divider } from 'ui';
|
||||
import { Background, Divider, HttpError } from 'ui';
|
||||
import type { WretchError } from 'wretch/types';
|
||||
|
||||
export async function generateMetadata({ params, searchParams }: PageProps): Promise<Metadata> {
|
||||
const createUrl = makeCreateUrl(`/${params.slug}`, searchParams);
|
||||
@ -21,20 +23,33 @@ export async function generateMetadata({ params, searchParams }: PageProps): Pro
|
||||
}
|
||||
|
||||
export default async function Page({ params, searchParams }: PageProps) {
|
||||
const createUrl = makeCreateUrl(`/${params.slug}`, searchParams);
|
||||
try {
|
||||
const createUrl = makeCreateUrl(`/${params.slug}`, searchParams);
|
||||
|
||||
const data = await apiIUS.getData(createUrl);
|
||||
const metaData = await apiIUS.getMetaData(createUrl);
|
||||
const { title } = await apiIUS.getConfig(createUrl);
|
||||
const data = await apiIUS.getData(createUrl);
|
||||
const metaData = await apiIUS.getMetaData(createUrl);
|
||||
const { title } = await apiIUS.getConfig(createUrl);
|
||||
|
||||
const props = { data, metaData, title };
|
||||
const props = { data, metaData, title };
|
||||
|
||||
return (
|
||||
<Background>
|
||||
<Form.Header {...props} url={'/ius' + createUrl('/conditions')} />
|
||||
<Form.Elements {...props} />
|
||||
<Divider />
|
||||
<Form.Buttons />
|
||||
</Background>
|
||||
);
|
||||
return (
|
||||
<Background>
|
||||
<Form.Header {...props} url={'/ius' + createUrl('/conditions')} />
|
||||
<Form.Elements {...props} />
|
||||
<Divider />
|
||||
<Form.Buttons />
|
||||
</Background>
|
||||
);
|
||||
} 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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user