improve graphql error handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Metadata, ResolvingMetadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { graphql } from "@/gql";
|
||||
import { ContactIndexFragment } from "@/gql/graphql";
|
||||
import { getClient } from "@/app/client";
|
||||
@@ -36,19 +37,30 @@ export async function generateMetadata(
|
||||
parent: ResolvingMetadata
|
||||
): Promise<Metadata | null> {
|
||||
const { data, error } = await getClient().query(contactQuery, {});
|
||||
const index = (data?.index ?? []) as ContactIndexFragment;
|
||||
|
||||
if (!index) {
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const index = data.index as ContactIndexFragment;
|
||||
const metadata = await getSeoMetadata(index, parent);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
export default async function Page() {
|
||||
const { data, error } = await getClient().query(contactQuery, {});
|
||||
const index = (data?.index ?? []) as ContactIndexFragment;
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.index) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const index = data.index as ContactIndexFragment;
|
||||
|
||||
return (
|
||||
<main className="site-main" id="main">
|
||||
|
||||
Reference in New Issue
Block a user