feat(core): shared domain error classes
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8248a2ac27
commit
27ec24eb4b
@@ -0,0 +1,42 @@
|
||||
/** Authentication or authorisation failure; `code` names the reason (e.g. "invalid_credentials"). */
|
||||
export class AuthError extends Error {
|
||||
override readonly name = "AuthError";
|
||||
constructor(readonly code: string) {
|
||||
super(code);
|
||||
}
|
||||
}
|
||||
|
||||
/** Input rejected by validation. */
|
||||
export class ValidationError extends Error {
|
||||
override readonly name = "ValidationError";
|
||||
readonly code = "validation";
|
||||
constructor(
|
||||
readonly field: string,
|
||||
readonly reason: string,
|
||||
) {
|
||||
super(`${field}: ${reason}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** Encryption or decryption failure (e.g. wrong key, tampered ciphertext). */
|
||||
export class CryptoError extends Error {
|
||||
override readonly name = "CryptoError";
|
||||
readonly code = "crypto";
|
||||
}
|
||||
|
||||
/** Import or restore failure; `code` names the reason. */
|
||||
export class ImportError extends Error {
|
||||
override readonly name = "ImportError";
|
||||
constructor(readonly code: string) {
|
||||
super(code);
|
||||
}
|
||||
}
|
||||
|
||||
/** A requested record does not exist (or is not visible to the caller). */
|
||||
export class NotFoundError extends Error {
|
||||
override readonly name = "NotFoundError";
|
||||
readonly code = "not_found";
|
||||
constructor(readonly what: string) {
|
||||
super(`${what} not found`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user