/** * Error vocabulary a {@link RecipeSourceAdapter} (recipe-source-adapter.ts) * implementation throws when talking to its source fails — kept separate * from `@batch-cooking/error-tools`'s `HttpError`/`ErrorCode` (used for * *this API's* HTTP responses) since no route drives this module yet. A * future import route would catch these and translate them into an * `HttpError` with a dedicated `ErrorCode` the same way any other service * error is; this module only needs a consistent shape to throw in the * meantime, not that translation. */ /** Base class for every error a {@link RecipeSourceAdapter} can throw — lets a caller `catch (err) { if (err instanceof RecipeSourceError) ... }` regardless of which stage failed. */ export class RecipeSourceError extends Error { /** The failing adapter's `key` (recipe-source-adapter.ts's `RecipeSourceAdapter.key`) — which source this error came from. */ readonly sourceKey: string; constructor(sourceKey: string, message: string, options?: { cause?: unknown }) { super(message, options); this.sourceKey = sourceKey; } } /** The source's `list`/`fetchDetail` failed — network error, non-2xx response, source unreachable, etc. */ export class RecipeSourceFetchError extends RecipeSourceError { constructor(sourceKey: string, message: string, options?: { cause?: unknown }) { super(sourceKey, message, options); this.name = "RecipeSourceFetchError"; } } /** The source responded, but `parse` couldn't make sense of the raw payload (unexpected shape, missing required field, …). */ export class RecipeSourceParseError extends RecipeSourceError { constructor(sourceKey: string, message: string, options?: { cause?: unknown }) { super(sourceKey, message, options); this.name = "RecipeSourceParseError"; } }