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

@@ -42,19 +42,30 @@ export async function generateMetadata(
parent: ResolvingMetadata
): Promise<Metadata | null> {
const { data, error } = await getClient().query(venueRentalIndexQuery, {});
const index = (data?.index ?? []) as VenueRentalIndexFragment;
if (!index) {
if (error) {
throw new Error(error.message);
}
if (!data?.index) {
return null;
}
const index = data.index as VenueRentalIndexFragment;
const metadata = await getSeoMetadata(index, parent);
return metadata;
}
export default async function Page() {
const { data, error } = await getClient().query(venueRentalIndexQuery, {});
const index = (data?.index ?? []) as VenueRentalIndexFragment;
if (error) {
throw new Error(error.message);
}
if (!data?.index || !data?.venues) {
throw new Error("Failed to render /utleie");
}
const index = data.index as VenueRentalIndexFragment;
const venues = (data?.venues ?? []) as VenueFragment[];
const bookableVenues = venues.filter((venue) => venue.showAsBookable);