@@ -3,7 +3,7 @@ import React from 'react';
3
3
import fetch from 'node-fetch' ;
4
4
import ReactDOMServer from 'react-dom/server' ;
5
5
import { ApolloProvider } from '@apollo/react-common' ;
6
- import { ApolloClient } from 'apollo-client' ;
6
+ import { ApolloClient , ApolloError } from 'apollo-client' ;
7
7
import { createHttpLink } from 'apollo-link-http' ;
8
8
import { InMemoryCache } from 'apollo-boost' ;
9
9
import { getDataFromTree } from '@apollo/react-ssr' ;
@@ -17,6 +17,7 @@ import Html from './Html';
17
17
import { ChunkExtractor , ChunkExtractorManager } from '@loadable/server' ;
18
18
import CacheManager from './CacheManager' ;
19
19
import { HelmetProvider , FilledContext } from 'react-helmet-async' ;
20
+ import error from '../modules/error' ;
20
21
21
22
const statsFile = path . resolve ( __dirname , '../build/loadable-stats.json' ) ;
22
23
const cacheManager = new CacheManager ( ) ;
@@ -94,6 +95,12 @@ const serverRender = async ({ url, loggedIn, cookie }: SSROption) => {
94
95
await getDataFromTree ( Root ) ;
95
96
} catch ( e ) {
96
97
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
+ }
97
104
console . log ( e ) ;
98
105
}
99
106
0 commit comments