From 859cf7b2b9fc4637e70034957aa053620f232c59 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Tue, 14 Nov 2023 11:07:09 +0300 Subject: [PATCH] apps/web: add http error to ius page --- apps/web/api/ius/types.ts | 6 +++++ apps/web/app/ius/[slug]/page.tsx | 43 +++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/apps/web/api/ius/types.ts b/apps/web/api/ius/types.ts index 50d1def..3076dea 100644 --- a/apps/web/api/ius/types.ts +++ b/apps/web/api/ius/types.ts @@ -14,3 +14,9 @@ export type ResponseGetData = Record; export type ResponseMetaData = Record; export type ResponseConfig = { title: string }; export type ResponseConditions = string; + +export type HttpError = { + errors: string[]; + status: number; + title: string; +}; diff --git a/apps/web/app/ius/[slug]/page.tsx b/apps/web/app/ius/[slug]/page.tsx index 3fe9459..7c79372 100644 --- a/apps/web/app/ius/[slug]/page.tsx +++ b/apps/web/app/ius/[slug]/page.tsx @@ -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 { 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 ( - - - - - - - ); + return ( + + + + + + + ); + } catch (error) { + const _error = error as WretchError; + const json = _error.json as t.HttpError; + + return ( + + ); + } }