34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
/**
|
|||
|
|
* Domain error types for the CMS module. Mirrors `cms/error.rs`.
|
||
|
|
*/
|
||
|
|
import type { DomainError } from "../core/error.ts";
|
||
|
|
|
||
|
|
/** Shared repository error type for CMS persistence. */
|
||
|
|
export type RepositoryError = DomainError;
|
||
|
|
|
||
|
|
/** Errors from service / use-case operations in the CMS domain. */
|
||
|
|
export type ServiceError =
|
||
|
|
| { kind: "repository"; error: DomainError }
|
||
|
|
| { kind: "invalid_input"; message: string }
|
||
|
|
| { kind: "other"; message: string };
|
||
|
|
|
||
|
|
export function cmsRepositoryErr(err: DomainError): ServiceError {
|
||
|
|
return { kind: "repository", error: err };
|
||
|
|
}
|
||
|
|
export function invalidInput(message: string): ServiceError {
|
||
|
|
return { kind: "invalid_input", message };
|
||
|
|
}
|
||
|
|
export function cmsOther(message: string): ServiceError {
|
||
|
|
return { kind: "other", message };
|
||
|
|
}
|
||
|
|
|
||
|
|
export function cmsServiceErrorToString(e: ServiceError): string {
|
||
|
|
switch (e.kind) {
|
||
|
|
case "repository":
|
||
|
|
return `repository error: ${e.error.message}`;
|
||
|
|
case "invalid_input":
|
||
|
|
return `invalid input: ${e.message}`;
|
||
|
|
case "other":
|
||
|
|
return e.message;
|
||
|
|
}
|
||
|
|
}
|