Better handling of article fetch errors

This commit is contained in:
Jackson Harper 2023-08-10 15:20:47 +08:00
parent 912210a097
commit 33fe595834

View file

@ -1,6 +1,11 @@
import { gql } from 'graphql-request'
import useSWRImmutable, { Cache } from 'swr'
import { gqlFetcher, makeGqlFetcher, RequestContext, ssrFetcher } from "../networkHelpers"
import {
gqlFetcher,
makeGqlFetcher,
RequestContext,
ssrFetcher,
} from '../networkHelpers'
import {
articleFragment,
ContentReader,
@ -130,14 +135,13 @@ export function useGetArticleQuery({
mutate: mutate,
articleData: resultData,
isLoading: !error && !data,
articleFetchError: resultError ? (resultError as string[]) : null,
articleFetchError: resultError ? Array(resultError) : null,
}
}
export async function articleQuery(
input: ArticleQueryInput
): Promise<ArticleAttributes | undefined> {
const result = (await gqlFetcher(query, input)) as ArticleData
if (result.article) {
return result.article.article