Skip to content

Commit

Permalink
Throw the error when site option is missing (#3956)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
esafev and FredKSchott authored Jul 18, 2022
1 parent 72e777a commit 57e529e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-glasses-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/rss': patch
---

Throw the error when 'site' option is missing
7 changes: 7 additions & 0 deletions packages/astro-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions packages/astro-rss/test/rss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 57e529e

Please sign in to comment.