Throw the error when site option is missing (#3956)

* Throw the error when site option is missing

* Update index.ts

* Update index.ts

* Update rss.test.js

* Update index.ts

Co-authored-by: Fred K. Schott <fkschott@gmail.com>
This commit is contained in:
Vlad Esafev 2022-07-19 02:01:04 +04:00 committed by GitHub
parent 72e777aad8
commit 57e529e4c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/rss': patch
---
Throw the error when 'site' option is missing

View file

@ -76,10 +76,17 @@ function mapGlobResult(items: GlobResult): Promise<RSSFeedItem[]> {
}
export default async function getRSS(rssOptions: RSSOptions) {
const { site } = rssOptions;
let { items } = rssOptions;
if (!site) {
throw new Error('[RSS] the "site" option is required, but no value was given.');
}
if (isGlobResult(items)) {
items = await mapGlobResult(items);
}
return {
body: await generateRSS({
rssOptions,

View file

@ -125,6 +125,20 @@ describe('rss', () => {
});
describe('errors', () => {
it('should provide a error message when a "site" option is missing', async () => {
try {
await rss({
title,
description,
items: [phpFeedItem, web1FeedItem]
});
chai.expect(false).to.equal(true, 'Should have errored');
} catch (err) {
chai.expect(err.message).to.contain('[RSS] the "site" option is required, but no value was given.');
}
});
it('should provide a good error message when a link is not provided', async () => {
try {
await rss({