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:
parent
72e777aad8
commit
57e529e4c1
3 changed files with 26 additions and 0 deletions
5
.changeset/many-glasses-roll.md
Normal file
5
.changeset/many-glasses-roll.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/rss': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Throw the error when 'site' option is missing
|
|
@ -76,10 +76,17 @@ function mapGlobResult(items: GlobResult): Promise<RSSFeedItem[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function getRSS(rssOptions: RSSOptions) {
|
export default async function getRSS(rssOptions: RSSOptions) {
|
||||||
|
const { site } = rssOptions;
|
||||||
let { items } = rssOptions;
|
let { items } = rssOptions;
|
||||||
|
|
||||||
|
if (!site) {
|
||||||
|
throw new Error('[RSS] the "site" option is required, but no value was given.');
|
||||||
|
}
|
||||||
|
|
||||||
if (isGlobResult(items)) {
|
if (isGlobResult(items)) {
|
||||||
items = await mapGlobResult(items);
|
items = await mapGlobResult(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
body: await generateRSS({
|
body: await generateRSS({
|
||||||
rssOptions,
|
rssOptions,
|
||||||
|
|
|
@ -125,6 +125,20 @@ describe('rss', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('errors', () => {
|
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 () => {
|
it('should provide a good error message when a link is not provided', async () => {
|
||||||
try {
|
try {
|
||||||
await rss({
|
await rss({
|
||||||
|
|
Loading…
Reference in a new issue