Skip to content

Commit 91bb4a5

Browse files
authored
Merge pull request velopert#131 from velopert/fix/user-page-404
Fix user page 404 page - velopert#129
2 parents f9f19c6 + 52abf38 commit 91bb4a5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/server/serverRender.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import fetch from 'node-fetch';
44
import ReactDOMServer from 'react-dom/server';
55
import { ApolloProvider } from '@apollo/react-common';
6-
import { ApolloClient } from 'apollo-client';
6+
import { ApolloClient, ApolloError } from 'apollo-client';
77
import { createHttpLink } from 'apollo-link-http';
88
import { InMemoryCache } from 'apollo-boost';
99
import { getDataFromTree } from '@apollo/react-ssr';
@@ -17,6 +17,7 @@ import Html from './Html';
1717
import { ChunkExtractor, ChunkExtractorManager } from '@loadable/server';
1818
import CacheManager from './CacheManager';
1919
import { HelmetProvider, FilledContext } from 'react-helmet-async';
20+
import error from '../modules/error';
2021

2122
const statsFile = path.resolve(__dirname, '../build/loadable-stats.json');
2223
const cacheManager = new CacheManager();
@@ -94,6 +95,12 @@ const serverRender = async ({ url, loggedIn, cookie }: SSROption) => {
9495
await getDataFromTree(Root);
9596
} catch (e) {
9697
console.log('Apollo Error! Rendering result anyways');
98+
if (e instanceof ApolloError) {
99+
const notFound = e.graphQLErrors.some(
100+
ge => (ge.extensions as any)?.code === 'NOT_FOUND',
101+
);
102+
if (notFound) store.dispatch(error.actions.showNotFound());
103+
}
97104
console.log(e);
98105
}
99106

0 commit comments

Comments
 (0)