graphql-request#ClientError TypeScript Examples
The following examples show how to use
graphql-request#ClientError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: [id].tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
export async function getStaticProps({
params,
}: GetStaticPropsContext<PostParams>): Promise<GetStaticPropsResult<Props>> {
const { id } = params;
try {
const postData = await request<PostData>(
`${apiUrl}/graphql`,
POST_BY_ID_STATIC_FIELDS_QUERY,
{ id },
);
return {
props: {
id,
postData,
},
revalidate: 60,
};
} catch (err) {
const clientError = err as ClientError;
if (clientError?.response?.errors?.[0]?.extensions?.code === 'NOT_FOUND') {
return {
props: { id: null },
revalidate: 60,
};
}
throw err;
}
}