improve graphql error handling
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user