Skip to content

Commit

Permalink
feat(app): handle feed.xml error
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jul 21, 2024
1 parent 53bb64e commit f8c1ee8
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/app/src/pages/feed.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,44 @@ export const GET: APIRoute = async (context) => {
feed.headers['cache-control'] = `public, max-age=300`;

return feed;
} else {
} else if (filter.success && filter.data.length === 0) {
// Empty response
const empty = await rss({
title: TITLE,
description: DESCRIPTION,
site: context.site!.origin,
trailingSlash: false,
items: []
});

return empty;
} else {
// Error
return new Response(
JSON.stringify({
status: 400,
detail: {
url: context.request.url,
filter: rawFilter.input,
message: filter.success === false ? filter.error.message : 'unknown'
}
}),
{ status: 400 }
);
}
} catch (error) {
console.error(error);
return new Response(JSON.stringify({ status: 400 }), { status: 400 });

return new Response(
JSON.stringify({
status: 400,
detail: {
url: context.request.url,
message: error?.message
}
}),
{ status: 400 }
);
}
};

Expand Down

0 comments on commit f8c1ee8

Please sign in to comment.