improve graphql error handling
This commit is contained in:
@ -27,12 +27,15 @@ export async function generateMetadata(
|
||||
const { data, error } = await getClient().query(associationBySlugQuery, {
|
||||
slug: params.slug,
|
||||
});
|
||||
const association = (data?.association ?? []) as AssociationFragment[];
|
||||
|
||||
if (!association) {
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.association) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const association = data.association as AssociationFragment;
|
||||
const metadata = await getSeoMetadata(association, parent);
|
||||
return metadata;
|
||||
}
|
||||
@ -48,11 +51,16 @@ export async function generateStaticParams() {
|
||||
`);
|
||||
const { data, error } = await getClient().query(allAssociationSlugsQuery, {});
|
||||
|
||||
if (data === undefined || error) {
|
||||
throw new Error("failed to generate static params");
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.pages) {
|
||||
throw new Error(
|
||||
"Failed to generate static params for subpages of /foreninger"
|
||||
);
|
||||
}
|
||||
|
||||
return data?.pages.map((page: any) => ({
|
||||
return data.pages.map((page: any) => ({
|
||||
slug: page.slug,
|
||||
}));
|
||||
}
|
||||
@ -62,11 +70,14 @@ export default async function Page({ params }: { params: { slug: string } }) {
|
||||
slug: params.slug,
|
||||
});
|
||||
|
||||
if (data?.association === null || error) {
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.association) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const association = (data?.association ?? {}) as AssociationFragment;
|
||||
const association = data.association as AssociationFragment;
|
||||
|
||||
return (
|
||||
<main className="site-main" id="main">
|
||||
|
Reference in New Issue
Block a user