Skip to content

Commit 57e529e

Browse files
esafevFredKSchott
andauthored
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 <[email protected]>
1 parent 72e777a commit 57e529e

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

.changeset/many-glasses-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/rss': patch
3+
---
4+
5+
Throw the error when 'site' option is missing

packages/astro-rss/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@ function mapGlobResult(items: GlobResult): Promise<RSSFeedItem[]> {
7676
}
7777

7878
export default async function getRSS(rssOptions: RSSOptions) {
79+
const { site } = rssOptions;
7980
let { items } = rssOptions;
81+
82+
if (!site) {
83+
throw new Error('[RSS] the "site" option is required, but no value was given.');
84+
}
85+
8086
if (isGlobResult(items)) {
8187
items = await mapGlobResult(items);
8288
}
89+
8390
return {
8491
body: await generateRSS({
8592
rssOptions,

packages/astro-rss/test/rss.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ describe('rss', () => {
125125
});
126126

127127
describe('errors', () => {
128+
it('should provide a error message when a "site" option is missing', async () => {
129+
try {
130+
await rss({
131+
title,
132+
description,
133+
items: [phpFeedItem, web1FeedItem]
134+
});
135+
136+
chai.expect(false).to.equal(true, 'Should have errored');
137+
} catch (err) {
138+
chai.expect(err.message).to.contain('[RSS] the "site" option is required, but no value was given.');
139+
}
140+
});
141+
128142
it('should provide a good error message when a link is not provided', async () => {
129143
try {
130144
await rss({

0 commit comments

Comments
 (0)