chore: Use status codes

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-04-07 00:21:08 +02:00
parent 6c10e738ec
commit ded7076874
No known key found for this signature in database
GPG Key ID: E59C7734F0E10EB5
2 changed files with 5 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import { nrkRadio, OriginalEpisode } from "../../../lib/nrk.ts"; import { nrkRadio, OriginalEpisode } from "../../../lib/nrk.ts";
import { FreshContext } from "$fresh/server.ts"; import { FreshContext, STATUS_CODE } from "$fresh/server.ts";
import { declaration, serialize, tag } from "https://raw.githubusercontent.com/olaven/serialize-xml/v0.4.0/mod.ts"; import { declaration, serialize, tag } from "https://raw.githubusercontent.com/olaven/serialize-xml/v0.4.0/mod.ts";
import { getHostName } from "../../../utils.ts"; import { getHostName } from "../../../utils.ts";
import { SeriesData } from "../../../lib/nrk.ts"; import { SeriesData } from "../../../lib/nrk.ts";
@ -90,7 +90,7 @@ export const handler = async (_req: Request, ctx: FreshContext): Promise<Respons
const seriesId = ctx.params.seriesId; const seriesId = ctx.params.seriesId;
const series = await nrkRadio.getSerieData(seriesId); const series = await nrkRadio.getSerieData(seriesId);
if (!series) { if (!series) {
return new Response(`Couldn't find series with seriesId: ${seriesId}`, { status: 404 }); return new Response(`Couldn't find series with seriesId: ${seriesId}`, { status: STATUS_CODE.NotFound });
} }
try { try {
const feedContent = buildFeed(series); const feedContent = buildFeed(series);
@ -103,7 +103,7 @@ export const handler = async (_req: Request, ctx: FreshContext): Promise<Respons
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return new Response(JSON.stringify({ message: "Could not generate feed" }), { return new Response(JSON.stringify({ message: "Could not generate feed" }), {
status: 500, status: STATUS_CODE.InternalServerError,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },

View File

@ -1,4 +1,4 @@
import { FreshContext } from "$fresh/server.ts"; import { FreshContext, STATUS_CODE } from "$fresh/server.ts";
import { parse, toSeconds } from "https://esm.sh/iso8601-duration@2.1.1"; import { parse, toSeconds } from "https://esm.sh/iso8601-duration@2.1.1";
import { nrkRadio, PodcastEpisode } from "../../../../../lib/nrk.ts"; import { nrkRadio, PodcastEpisode } from "../../../../../lib/nrk.ts";
@ -29,7 +29,7 @@ export const handler = async (_req: Request, ctx: FreshContext): Promise<Respons
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
status: 500, status: STATUS_CODE.NotFound,
}); });
} }
const chapters = toChapters(episode); const chapters = toChapters(episode);