batchCooking/apps/api/src/lib/recipe-sources/recipe-source-errors.ts
Nicolas 4db8e1369f refactor(api): regroupe lib/ par sous-domaine au lieu d'un dossier à plat
9 fichiers à plat -> recipe-sources/ (recipe-source-adapter, recipe-source-
errors, recipe-source-registry) et recipe-matching/ (recipe-translation,
ingredient-matcher, tech-step-matcher). jwt.ts, safe-profile.ts et
logger.service.ts restent à la racine de lib/ (pas de sous-domaine
partagé avec les autres).

Chemins relatifs corrigés dans les fichiers déplacés (profondeur +1 vers
db/) et chez tous leurs importeurs (modules/sources, modules/recipe,
sources/*, db/recipe-source-sync.ts, 12 fichiers de test), doc mise à
jour (specs/backend-architecture.md, specs/batch-cooking-architecture.md).

Vérifié : tsc --noEmit, biome check, build complet, 303 tests API.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-21 11:21:49 +02:00

37 lines
1.8 KiB
TypeScript

/**
* 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";
}
}