-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy patherror-decoder-page.tsx
More file actions
64 lines (60 loc) · 1.95 KB
/
error-decoder-page.tsx
File metadata and controls
64 lines (60 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import fsp from 'node:fs/promises';
import fs from 'node:fs';
import {Page} from '../../../components/Layout/Page';
import sidebarLearn from 'sidebarLearn.json';
import type {RouteItem} from '../../../components/Layout/getRouteMeta';
import {notFound} from 'next/navigation';
import {join} from 'node:path';
import compileMDX from '../../../utils/compileMDX';
import ErrorMDX from './error-mdx';
export default async function ErrorDecoderPage({
errorCode,
errorCodes,
}: {
errorCode: string | null;
errorCodes: {[key: string]: string};
}) {
if (errorCode && !errorCodes[errorCode]) {
notFound();
}
const rootDir = join(process.cwd(), 'src', 'content', 'errors');
let path = errorCode || 'index';
let mdx;
if (fs.existsSync(join(rootDir, path + '.md'))) {
mdx = await fsp.readFile(join(rootDir, path + '.md'), 'utf8');
} else {
mdx = await fsp.readFile(join(rootDir, 'generic.md'), 'utf8');
}
const {content} = await compileMDX(mdx, path, {code: errorCode, errorCodes});
const errorMessage = errorCode ? errorCodes[errorCode] : null;
return (
<Page
toc={[]}
meta={{
title: errorCode
? 'Minified React error #' + errorCode
: 'Minified Error Decoder',
}}
routeTree={sidebarLearn as RouteItem}
section="unknown"
appRouter>
<div>
<ErrorMDX
content={content}
errorCode={errorCode}
errorMessage={errorMessage}
/>
</div>
{/* <MaxWidth>
<P>
We highly recommend using the development build locally when debugging
your app since it tracks additional debug info and provides helpful
warnings about potential problems in your apps, but if you encounter
an exception while using the production build, this page will
reassemble the original error message.
</P>
<ErrorDecoder />
</MaxWidth> */}
</Page>
);
}