mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 19:03:38 +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',
|
||||
toRoutePath: '/toSomePath',
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"fromRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string"`,
|
||||
);
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
|
||||
expect(() =>
|
||||
validateRedirect({
|
||||
fromRoutePath: '/fromSomePath',
|
||||
toRoutePath: 'https://fb.com/toSomePath',
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"toRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string"`,
|
||||
);
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
|
||||
expect(() =>
|
||||
validateRedirect({
|
||||
fromRoutePath: '/fromSomePath',
|
||||
toRoutePath: '/toSomePath?queryString=xyz',
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"toRoutePath is not a valid pathname. Pathname should start with / and not contain any domain or query string"`,
|
||||
);
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,5 +22,10 @@ const RedirectSchema = Yup.object<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