mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-04 11:52:39 +02:00
add context to error message
This commit is contained in:
parent
5bf85e44ac
commit
a0991c581b
3 changed files with 25 additions and 10 deletions
|
@ -0,0 +1,16 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`validateRedirect throw for bad redirects 1`] = `
|
||||||
|
"fromRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string
|
||||||
|
Redirect={\\"fromRoutePath\\":\\"https://fb.com/fromSomePath\\",\\"toRoutePath\\":\\"/toSomePath\\"}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`validateRedirect throw for bad redirects 2`] = `
|
||||||
|
"toRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string
|
||||||
|
Redirect={\\"fromRoutePath\\":\\"/fromSomePath\\",\\"toRoutePath\\":\\"https://fb.com/toSomePath\\"}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`validateRedirect throw for bad redirects 3`] = `
|
||||||
|
"toRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string
|
||||||
|
Redirect={\\"fromRoutePath\\":\\"/fromSomePath\\",\\"toRoutePath\\":\\"/toSomePath?queryString=xyz\\"}"
|
||||||
|
`;
|
|
@ -33,26 +33,20 @@ describe('validateRedirect', () => {
|
||||||
fromRoutePath: 'https://fb.com/fromSomePath',
|
fromRoutePath: 'https://fb.com/fromSomePath',
|
||||||
toRoutePath: '/toSomePath',
|
toRoutePath: '/toSomePath',
|
||||||
}),
|
}),
|
||||||
).toThrowErrorMatchingInlineSnapshot(
|
).toThrowErrorMatchingSnapshot();
|
||||||
`"fromRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string"`,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(() =>
|
expect(() =>
|
||||||
validateRedirect({
|
validateRedirect({
|
||||||
fromRoutePath: '/fromSomePath',
|
fromRoutePath: '/fromSomePath',
|
||||||
toRoutePath: 'https://fb.com/toSomePath',
|
toRoutePath: 'https://fb.com/toSomePath',
|
||||||
}),
|
}),
|
||||||
).toThrowErrorMatchingInlineSnapshot(
|
).toThrowErrorMatchingSnapshot();
|
||||||
`"toRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string"`,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(() =>
|
expect(() =>
|
||||||
validateRedirect({
|
validateRedirect({
|
||||||
fromRoutePath: '/fromSomePath',
|
fromRoutePath: '/fromSomePath',
|
||||||
toRoutePath: '/toSomePath?queryString=xyz',
|
toRoutePath: '/toSomePath?queryString=xyz',
|
||||||
}),
|
}),
|
||||||
).toThrowErrorMatchingInlineSnapshot(
|
).toThrowErrorMatchingSnapshot();
|
||||||
`"toRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string"`,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,5 +22,10 @@ const RedirectSchema = Yup.object<RedirectMetadata>({
|
||||||
});
|
});
|
||||||
|
|
||||||
export function validateRedirect(redirect: RedirectMetadata) {
|
export function validateRedirect(redirect: RedirectMetadata) {
|
||||||
RedirectSchema.validateSync(redirect);
|
try {
|
||||||
|
RedirectSchema.validateSync(redirect);
|
||||||
|
} catch (e) {
|
||||||
|
// Tells the user which redirect is the problem!
|
||||||
|
throw new Error(`${e.message}\nRedirect=${JSON.stringify(redirect)}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue