improve graphql error handling

This commit is contained in:
2024-08-14 22:13:49 +02:00
parent 137a8c0b2f
commit 27477de14e
11 changed files with 175 additions and 61 deletions

View File

@ -30,12 +30,15 @@ export async function generateMetadata(
parent: ResolvingMetadata
): Promise<Metadata | null> {
const { data, error } = await getClient().query(allAssociationsQuery, {});
const index = (data?.index ?? []) as AssociationIndexFragment;
if (!index) {
if (error) {
throw new Error(error.message);
}
if (!data?.index) {
return null;
}
const index = data.index as AssociationIndexFragment;
const metadata = await getSeoMetadata(index, parent);
return metadata;
}
@ -79,8 +82,16 @@ const AssociationFragmentDefinition = graphql(`
export default async function Page() {
const { data, error } = await getClient().query(allAssociationsQuery, {});
const associations = (data?.associations ?? []) as AssociationFragment[];
const index = (data?.index ?? []) as AssociationIndexFragment;
if (error) {
throw new Error(error.message);
}
if (!data?.associations || !data.index) {
throw new Error("Failed to render /foreninger");
}
const associations = data.associations as AssociationFragment[];
const index = data.index as AssociationIndexFragment;
return (
<main className="site-main" id="main">