Skip to content

Commit 45e472c

Browse files
committed
Fix /error being 404
1 parent 29f4eaa commit 45e472c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/components/MDX/ErrorDecoderContext.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
import {createContext, useContext} from 'react';
77

8-
export const ErrorDecoderContext = createContext<string | null>(null);
8+
const notInErrorDecoderContext = Symbol('not in error decoder context');
9+
10+
export const ErrorDecoderContext = createContext<
11+
string | null | typeof notInErrorDecoderContext
12+
>(notInErrorDecoderContext);
913

1014
export const useErrorDecoder = () => {
1115
const errorMessages = useContext(ErrorDecoderContext);
1216

13-
if (errorMessages === null) {
17+
if (errorMessages === notInErrorDecoderContext) {
1418
throw new Error('useErrorDecoder must be used in error decoder pages only');
1519
}
1620

src/pages/errors/[error_code].tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const getStaticProps: GetStaticProps<ErrorDecoderProps> = async ({
9595

9696
const code =
9797
typeof params?.error_code === 'string' ? params?.error_code : null;
98-
if (!code || !errorCodes[code]) {
98+
if (code && !errorCodes[code]) {
9999
return {
100100
notFound: true,
101101
};
@@ -142,6 +142,7 @@ export const getStaticProps: GetStaticProps<ErrorDecoderProps> = async ({
142142
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143143
mdx,
144144
mdxComponentNames,
145+
code,
145146
DISK_CACHE_BREAKER,
146147
PREPARE_MDX_CACHE_BREAKER,
147148
lockfile: fs.readFileSync(process.cwd() + '/yarn.lock', 'utf8'),
@@ -170,8 +171,6 @@ export const getStaticProps: GetStaticProps<ErrorDecoderProps> = async ({
170171
.map((key) => 'import ' + key + ' from "' + key + '";\n')
171172
.join('\n');
172173

173-
console.log({mdxComponentNames});
174-
175174
// Turn the MDX we just read into some JS we can execute.
176175
const {remarkPlugins} = require('../../../plugins/markdownToHtml');
177176
const {compile: compileMdx} = await import('@mdx-js/mdx');
@@ -240,7 +239,7 @@ export const getStaticProps: GetStaticProps<ErrorDecoderProps> = async ({
240239
props: {
241240
content: JSON.stringify(children, stringifyNodeOnServer),
242241
errorCode: code,
243-
errorMessages: errorCodes[code],
242+
errorMessages: code ? errorCodes[code] : null,
244243
toc: JSON.stringify(toc, stringifyNodeOnServer),
245244
meta,
246245
},

src/pages/errors/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import ErrorDecoderPage from './[error_code]';
22
export default ErrorDecoderPage;
3+
export {getStaticProps} from './[error_code]';

0 commit comments

Comments
 (0)