Skip to content

Commit 1d4d394

Browse files
committed
Add error message page
1 parent cf6a2e9 commit 1d4d394

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

website/sidebars.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
"api/createSelector",
7676
"api/matching-utilities",
7777
"api/other-exports",
78-
"api/codemods"
78+
"api/codemods",
79+
{ "type": "link", "label": "Error Messages", "href": "/errors" }
7980
]
8081
}
8182
]

website/src/pages/errors.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react'
2+
import Layout from '@theme/Layout'
3+
import { useLocation } from '@docusaurus/router'
4+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
5+
import styles from './styles.module.css'
6+
import errorCodes from '../../../errors.json'
7+
8+
function Errors() {
9+
const location = useLocation()
10+
const context = useDocusaurusContext()
11+
const { siteConfig = {} } = context
12+
const errorCode = new URLSearchParams(location.search).get('code')
13+
const error = errorCodes[errorCode]
14+
15+
return (
16+
<Layout
17+
title={`${siteConfig.title} - ${siteConfig.tagline}`}
18+
description={siteConfig.tagline}
19+
>
20+
<main className={styles.mainFull}>
21+
<h1>Production Error Codes</h1>
22+
<p>
23+
When Redux Toolkit is built and running in production, error text is
24+
replaced by indexed error codes to save on bundle size. These errors
25+
will provide a link to this page with more information about the error
26+
below.
27+
</p>
28+
{error && (
29+
<React.Fragment>
30+
<p>
31+
<strong>
32+
The full text of the error you just encountered is:
33+
</strong>
34+
</p>
35+
<code className={styles.errorDetails}>{error}</code>
36+
</React.Fragment>
37+
)}
38+
39+
<h2>All Error Codes</h2>
40+
<table>
41+
<thead>
42+
<tr>
43+
<th>Code</th>
44+
<th>Message</th>
45+
</tr>
46+
</thead>
47+
<tbody>
48+
{Object.keys(errorCodes).map((code) => (
49+
<tr>
50+
<td>{code}</td>
51+
<td>{errorCodes[code]}</td>
52+
</tr>
53+
))}
54+
</tbody>
55+
</table>
56+
</main>
57+
</Layout>
58+
)
59+
}
60+
61+
export default Errors

website/src/pages/styles.module.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,32 @@
8080
font-size: 30px;
8181
margin-bottom: 55px;
8282
}
83+
84+
.mainFull {
85+
padding: 34px 16px;
86+
width: 100%;
87+
max-width: var(--ifm-container-width);
88+
margin: 0px auto;
89+
}
90+
.mainFull h1 {
91+
font-size: 3rem;
92+
color: var(--ifm-heading-color);
93+
font-weight: var(--ifm-heading-font-weight);
94+
line-height: var(--ifm-heading-line-height);
95+
}
96+
97+
.mainFull p {
98+
margin-bottom: var(--ifm-leading);
99+
margin-top: 0;
100+
}
101+
102+
103+
.errorDetails {
104+
color: #ff6464;
105+
border-radius: 0.5rem;
106+
padding: 1rem;
107+
margin: 30px 0;
108+
font-weight: bold;
109+
background-color: rgba(255, 100, 100, 0.1);
110+
display: block;
111+
}

0 commit comments

Comments
 (0)