Skip to content

Commit 753d2c7

Browse files
author
Brian Vaughn
committed
Fixed broken error decoder route
1 parent 3e0073c commit 753d2c7

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

gatsby/createPages.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = async (params) => {
5959
const {fields} = edge.node;
6060
let {id, language, languageCode, slug} = fields;
6161

62-
if (slug === 'docs/error-decoder.html') {
62+
if (slug === '/docs/error-decoder.html') {
6363
// No-op so far as markdown templates go.
6464
// Error codes are managed by a page in src/pages
6565
// (which gets created by Gatsby during a separate phase).

gatsby/onCreatePage.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ module.exports = async ({page, boundActionCreators}) => {
1212
return new Promise(resolvePromise => {
1313
// page.matchPath is a special key that's used for matching pages only on the client.
1414
// Explicitly wire up all error code wildcard matches to redirect to the error code page.
15-
if (page.path.includes('docs/error-decoder.html')) {
16-
page.matchPath = 'docs/error-decoder:path?';
17-
page.context.slug = 'docs/error-decoder.html';
15+
if (page.path.includes('/docs/error-decoder.html')) {
16+
page.matchPath = '/docs/error-decoder:path?';
17+
page.context.slug = '/docs/error-decoder.html';
1818

1919
createPage(page);
2020
}

src/components/ErrorDecoder/ErrorDecoder.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ function urlify(str: string): Node {
3939
// `?invariant=123&args[]=foo&args[]=bar`
4040
// or `// ?invariant=123&args[0]=foo&args[1]=bar`
4141
function parseQueryString(
42-
search: string,
42+
search: ?string,
4343
): ?{|code: string, args: Array<string>|} {
44-
const rawQueryString = search.substring(1);
44+
const rawQueryString = search ? search.substring(1) : null;
4545
if (!rawQueryString) {
4646
return null;
4747
}
@@ -89,13 +89,15 @@ function ErrorResult(props: {|code: ?string, msg: string|}) {
8989

9090
function ErrorDecoder(props: {|
9191
errorCodesString: string,
92-
location: {search: string},
92+
location: {search: ?string},
9393
|}) {
9494
let code = null;
9595
let msg = '';
9696

97-
const errorCodes = JSON.parse(props.errorCodesString);
98-
const parseResult = parseQueryString(props.location.search);
97+
const {errorCodesString, location} = props;
98+
99+
const errorCodes = JSON.parse(errorCodesString);
100+
const parseResult = parseQueryString(location.search);
99101
if (parseResult != null) {
100102
code = parseResult.code;
101103
msg = replaceArgs(errorCodes[code], parseResult.args);

src/pages/docs/error-decoder.html.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ const ErrorPage = ({data, location}: Props) => (
100100

101101
// eslint-disable-next-line no-undef
102102
export const pageQuery = graphql`
103-
query ErrorPageMarkdown($slug: String!) {
104-
markdownRemark(fields: {slug: {eq: $slug}}) {
103+
query ErrorPageMarkdown {
104+
markdownRemark(fields: {slug: {eq: "/docs/error-decoder.html"}}) {
105105
html
106106
fields {
107107
path

0 commit comments

Comments
 (0)