From bafc27c1a7ad21889d6fa230a711f6887bc99b35 Mon Sep 17 00:00:00 2001 From: Matt Leon <108271225+wydengyre@users.noreply.github.com> Date: Sat, 27 Jan 2024 12:30:18 +0700 Subject: [PATCH] factor-out-errors (#17) factor out NotFoundError Move from feed.ts to error.ts. --- lib/error.ts | 6 ++++++ lib/feed-handler.ts | 3 ++- lib/feed.test.ts | 2 +- lib/feed.ts | 8 +------- 4 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 lib/error.ts diff --git a/lib/error.ts b/lib/error.ts new file mode 100644 index 0000000..fc65893 --- /dev/null +++ b/lib/error.ts @@ -0,0 +1,6 @@ +export class NotFoundError extends Error { + constructor(url: URL) { + super(`Not found: ${url}`); + this.name = "NotFoundError"; + } +} diff --git a/lib/feed-handler.ts b/lib/feed-handler.ts index c635fde..e67c40b 100644 --- a/lib/feed-handler.ts +++ b/lib/feed-handler.ts @@ -1,5 +1,6 @@ import { createResponse } from "itty-router"; -import { NotFoundError, convertFeed } from "./feed.js"; +import { NotFoundError } from "./error.js"; +import { convertFeed } from "./feed.js"; import { Logger } from "./logger.js"; type Config = { diff --git a/lib/feed.test.ts b/lib/feed.test.ts index b8282d1..ed57203 100644 --- a/lib/feed.test.ts +++ b/lib/feed.test.ts @@ -1,13 +1,13 @@ import { strict as assert } from "node:assert"; import test from "node:test"; import { error, json } from "itty-router"; +import { NotFoundError } from "./error.js"; import { Convertor, ConvertorConf, FeedConf, FeedFetcher, FetcherConf, - NotFoundError, convertFeed, } from "./feed.js"; import { Fetcher as MediaFetcher } from "./media.js"; diff --git a/lib/feed.ts b/lib/feed.ts index f5d9809..5f4c175 100644 --- a/lib/feed.ts +++ b/lib/feed.ts @@ -1,6 +1,7 @@ import { PromisePool } from "@supercharge/promise-pool"; import { z } from "zod"; import { Podcast } from "../build/podcast/index.js"; +import { NotFoundError } from "./error.js"; import { Fetcher as MediaFetcher } from "./media.js"; const cardSchema = z.object({ @@ -77,13 +78,6 @@ export class FeedFetcher { } } -export class NotFoundError extends Error { - constructor(url: URL) { - super(`Not found: ${url}`); - this.name = "NotFoundError"; - } -} - export type ConvertorConf = { raiBaseUrl: URL; poolSize: number;