diff --git a/src/pages/index.page.tsx b/src/pages/index.page.tsx index 65315c798..99d38472f 100644 --- a/src/pages/index.page.tsx +++ b/src/pages/index.page.tsx @@ -2,7 +2,7 @@ import { GetServerSideProps, GetServerSidePropsContext } from 'next'; import { fetchTenantUsingContext, fetchVersions } from '../utils/data-fetch'; import { ArticleSummary } from '../types'; import { Heading } from '../components/atoms/heading/heading'; -import { HasTenant } from '../tenant'; +import { HasTenant, TenantData } from '../tenant'; type PageProps = HasTenant & { ids?: string[], @@ -35,7 +35,12 @@ export const App = ({ ids, articles, previews }: PageProps) => ( ); export const getServerSideProps: GetServerSideProps = async (context: GetServerSidePropsContext) => { - const tenant = await fetchTenantUsingContext(context); + let tenant: TenantData; + try { + tenant = await fetchTenantUsingContext(context); + } catch (e) { + return { notFound: true }; + } const versions = (await fetchVersions(tenant.id)).items.sort((a, b) => (a.id > b.id ? 1 : -1)); const articles = versions.filter((version) => (version.date)); diff --git a/src/pages/reviewed-preprints/[...path].page.tsx b/src/pages/reviewed-preprints/[...path].page.tsx index 43e21be97..a38e360c5 100644 --- a/src/pages/reviewed-preprints/[...path].page.tsx +++ b/src/pages/reviewed-preprints/[...path].page.tsx @@ -23,7 +23,7 @@ import { ErrorMessages } from '../../components/atoms/error-messages/error-messa import { formatAuthorName } from '../../utils/formatters'; import { makeNullableOptional } from '../../utils/make-nullable-optional'; import { SerialisedTimelineEvent } from '../../types/article-timeline'; -import { HasTenant } from '../../tenant'; +import { HasTenant, TenantData } from '../../tenant'; type PageProps = HasTenant & { metaData: MetaData, @@ -179,7 +179,12 @@ export const getServerSideProps: GetServerSideProps = async (context: return { notFound: true }; } - const tenant = await fetchTenantUsingContext(context); + let tenant: TenantData; + try { + tenant = await fetchTenantUsingContext(context); + } catch (e) { + return { notFound: true }; + } const idParts = [...context.params?.path as string[]]; diff --git a/src/utils/data-fetch/fetch-data.ts b/src/utils/data-fetch/fetch-data.ts index 45e98ca2b..431e9615b 100644 --- a/src/utils/data-fetch/fetch-data.ts +++ b/src/utils/data-fetch/fetch-data.ts @@ -4,7 +4,7 @@ import { ArticleSummary, EnhancedArticleWithVersions } from '../../types'; import { EnhancedArticleNoContent } from '../../types/reviewed-preprint-snippet'; import { TenantData } from '../../tenant'; -export const fetchTenant = (tenantId: string) => jsonFetch(`${config.apiServer}/api/${tenantId}/config`); +export const fetchTenant = (tenantId: string) => jsonFetchOrNull(`${config.apiServer}/api/${tenantId}/config`); export const fetchVersion = (tenantId: string, id: string, preview: boolean = false) => jsonFetchOrNull(`${config.apiServer}/api/${tenantId}/preprints/${id}${preview ? '?previews=true' : ''}`); export const fetchVersions = (tenantId: string) => jsonFetch<{ items: ArticleSummary[], total: number }>(`${config.apiServer}/api/${tenantId}/preprints`); export const fetchVersionsNoContent = async (tenantId: string, page: number, perPage: number, order: 'asc' | 'desc', useDate: 'default' | 'published', startDate: string, endDate: string) => {