feat(domain): complete phase 2 backend core

This commit is contained in:
poyrazavsever
2026-07-16 16:46:42 +03:00
parent 92bc99ba12
commit b155132acf
28 changed files with 5343 additions and 30 deletions
+38
View File
@@ -0,0 +1,38 @@
export type DomainErrorCode =
| "VALIDATION_ERROR"
| "UNAUTHENTICATED"
| "FORBIDDEN"
| "NOT_FOUND"
| "CONFLICT"
| "INVARIANT_VIOLATION";
const statusByCode: Record<DomainErrorCode, number> = {
VALIDATION_ERROR: 400,
UNAUTHENTICATED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
CONFLICT: 409,
INVARIANT_VIOLATION: 422,
};
export class DomainError extends Error {
readonly status: number;
constructor(
public readonly code: DomainErrorCode,
message: string,
public readonly details?: Record<string, unknown>,
) {
super(message);
this.name = "DomainError";
this.status = statusByCode[code];
}
}
export function notFound(resource = "Kaynak"): DomainError {
return new DomainError("NOT_FOUND", `${resource} bulunamadı.`);
}
export function conflict(message: string): DomainError {
return new DomainError("CONFLICT", message);
}