fix: Add error message when unable to generate feed
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
77428d374a
commit
ab5c1b9e56
|
|
@ -47,6 +47,7 @@ export const nrkRadio = {
|
||||||
searchComponents["schemas"]["searchresult"]
|
searchComponents["schemas"]["searchresult"]
|
||||||
>(`https://psapi.nrk.no/radio/search/search?q=${query}`);
|
>(`https://psapi.nrk.no/radio/search/search?q=${query}`);
|
||||||
if (status === OK && response) {
|
if (status === OK && response) {
|
||||||
|
console.log("res", response.results);
|
||||||
return response.results.series?.results;
|
return response.results.series?.results;
|
||||||
} else {
|
} else {
|
||||||
throw `Something went wrong with ${query} - got status ${status}`;
|
throw `Something went wrong with ${query} - got status ${status}`;
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ async function buildFeed(seriesId: string) {
|
||||||
|
|
||||||
export const handler = async (_req: Request, ctx: FreshContext): Promise<Response> => {
|
export const handler = async (_req: Request, ctx: FreshContext): Promise<Response> => {
|
||||||
const seriesId = ctx.params.seriesId;
|
const seriesId = ctx.params.seriesId;
|
||||||
|
try {
|
||||||
const feedContent = await buildFeed(seriesId);
|
const feedContent = await buildFeed(seriesId);
|
||||||
|
|
||||||
return new Response(feedContent, {
|
return new Response(feedContent, {
|
||||||
|
|
@ -95,4 +96,13 @@ export const handler = async (_req: Request, ctx: FreshContext): Promise<Respons
|
||||||
"Content-Type": "application/xml",
|
"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",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue