refactor: 도메인이 100개 1000개씩 늘어나도 유지보수 쉬운 구조로 변경
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import {
|
||||
defineAppError,
|
||||
type AppError,
|
||||
} from "../../../platform/errors/app-error.ts";
|
||||
import type { ApiFailure } from "../../../contracts/errors.ts";
|
||||
|
||||
/**
|
||||
* Spec §17–§19. The reference feature's own domain errors.
|
||||
*
|
||||
* This union is local to the feature. It satisfies the platform `AppError`
|
||||
* envelope structurally; nothing central enumerates it, so adding or removing
|
||||
* this feature never edits a shared error type.
|
||||
*/
|
||||
export type ReferenceError =
|
||||
| (AppError & {
|
||||
readonly kind: "reference.not-found";
|
||||
readonly category: "domain";
|
||||
readonly severity: "warning";
|
||||
readonly retryability: "never";
|
||||
})
|
||||
| (AppError & {
|
||||
readonly kind: "reference.conflict";
|
||||
readonly category: "domain";
|
||||
readonly severity: "warning";
|
||||
readonly retryability: "never";
|
||||
})
|
||||
| (AppError & {
|
||||
readonly kind: "reference.rejected";
|
||||
readonly category: "validation";
|
||||
readonly severity: "warning";
|
||||
readonly retryability: "never";
|
||||
});
|
||||
|
||||
export const REFERENCE_ERRORS = Object.freeze({
|
||||
NOT_FOUND: defineAppError({
|
||||
kind: "reference.not-found",
|
||||
category: "domain",
|
||||
severity: "warning",
|
||||
retryability: "never",
|
||||
}),
|
||||
CONFLICT: defineAppError({
|
||||
kind: "reference.conflict",
|
||||
category: "domain",
|
||||
severity: "warning",
|
||||
retryability: "never",
|
||||
}),
|
||||
REJECTED: defineAppError({
|
||||
kind: "reference.rejected",
|
||||
category: "validation",
|
||||
severity: "warning",
|
||||
retryability: "never",
|
||||
}),
|
||||
} satisfies Record<string, ReferenceError>);
|
||||
|
||||
/**
|
||||
* Interprets a transport-normalized failure in this feature's own vocabulary.
|
||||
* Anything that is not a reference domain outcome stays `null`: the platform
|
||||
* error mapping, not this feature, owns transport/contract failures.
|
||||
*/
|
||||
export function toReferenceError(failure: ApiFailure): ReferenceError | null {
|
||||
switch (failure.kind) {
|
||||
case "NOT_FOUND":
|
||||
return REFERENCE_ERRORS.NOT_FOUND;
|
||||
case "CONFLICT":
|
||||
return REFERENCE_ERRORS.CONFLICT;
|
||||
case "VALIDATION_REJECTED":
|
||||
return REFERENCE_ERRORS.REJECTED;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user