fix: Add error message when unable to generate feed

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-03-30 15:17:35 +01:00
parent 77428d374a
commit ab5c1b9e56
No known key found for this signature in database
GPG Key ID: E59C7734F0E10EB5
2 changed files with 17 additions and 6 deletions

View File

@ -47,6 +47,7 @@ export const nrkRadio = {
searchComponents["schemas"]["searchresult"]
>(`https://psapi.nrk.no/radio/search/search?q=${query}`);
if (status === OK && response) {
console.log("res", response.results);
return response.results.series?.results;
} else {
throw `Something went wrong with ${query} - got status ${status}`;

View File

@ -88,11 +88,21 @@ async function buildFeed(seriesId: string) {
export const handler = async (_req: Request, ctx: FreshContext): Promise<Response> => {
const seriesId = ctx.params.seriesId;
const feedContent = await buildFeed(seriesId);
try {
const feedContent = await buildFeed(seriesId);
return new Response(feedContent, {
headers: {
"Content-Type": "application/xml",
},
});
return new Response(feedContent, {
headers: {
"Content-Type": "application/xml",
},
});
} catch (error) {
console.error(error);
return new Response(JSON.stringify({ message: "Could not generate feed" }), {
status: 500,
headers: {
"Content-Type": "application/json",
},
});
}
};