mirror of
https://github.com/withastro/astro.git
synced 2025-03-17 23:11:29 -05:00
[@astrojs/rss] Quality-of-Life Improvement to items
property-related error (#9299)
* This commit addresses a quality-of-life concern when setting up a RSS feed when using collections. Specifically, it provides more context to the error message thrown when the object passed to the `items` property is missing any of the three required keys or if one of those keys is mistyped. * Add changeset * Update .changeset with properly formatted update structure @sarah11918 suggested a change to the verbiage that properly formatted the update detail in question. Accepting the suggestion. Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
parent
eb942942d6
commit
edfae50e6e
2 changed files with 20 additions and 2 deletions
5
.changeset/thirty-hairs-pump.md
Normal file
5
.changeset/thirty-hairs-pump.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/rss': patch
|
||||
---
|
||||
|
||||
Improves the `@astrojs/rss` error message thrown when the object passed to the `items` property is missing any of the three required keys or if one of those keys is mistyped.
|
|
@ -110,8 +110,21 @@ async function validateRssOptions(rssOptions: RSSOptions) {
|
|||
[
|
||||
`[RSS] Invalid or missing options:`,
|
||||
...parsedResult.error.errors.map(
|
||||
(zodError) => `${zodError.message} (${zodError.path.join('.')})`
|
||||
),
|
||||
(zodError) => {
|
||||
const path = zodError.path.join('.');
|
||||
const message = `${zodError.message} (${path})`;
|
||||
const code = zodError.code;
|
||||
|
||||
if (path === 'items' && code === 'invalid_union') {
|
||||
return [
|
||||
message,
|
||||
`The \`items\` property requires properly typed \`title\`, \`pubDate\`, and \`link\` keys.`,
|
||||
`Check your collection's schema, and visit https://docs.astro.build/en/guides/rss/#generating-items for more info.`
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
return message;
|
||||
}),
|
||||
].join('\n')
|
||||
);
|
||||
throw formattedError;
|
||||
|
|
Loading…
Add table
Reference in a new issue