refactor: 도메인이 100개 1000개씩 늘어나도 유지보수 쉬운 구조로 변경
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import type { AppError } from "../../platform/errors/app-error.ts";
|
||||
import { PLATFORM_ERRORS } from "../../platform/errors/platform-errors.ts";
|
||||
import type { HttpExecutionOutcome } from "./http-execution-v3.ts";
|
||||
|
||||
/**
|
||||
* Spec §17. Adapter-boundary normalization of transport-level outcomes into
|
||||
* the platform error envelope. Only failures no feature owns are mapped here;
|
||||
* a `PROBLEM`, an auth verdict or a scope fence is interpreted by its owner
|
||||
* (the feature binding or the session), so those return `null`.
|
||||
*/
|
||||
export function platformErrorForOutcome(
|
||||
outcome: HttpExecutionOutcome<unknown, unknown>,
|
||||
): AppError | null {
|
||||
switch (outcome.kind) {
|
||||
case "CANCELLED":
|
||||
return PLATFORM_ERRORS.REQUEST_CANCELLED;
|
||||
case "TRANSPORT_FAILURE":
|
||||
switch (outcome.failure.kind) {
|
||||
case "TIMEOUT":
|
||||
return PLATFORM_ERRORS.REQUEST_TIMEOUT;
|
||||
case "ABORTED_BY_CALLER":
|
||||
return PLATFORM_ERRORS.REQUEST_CANCELLED;
|
||||
case "OVERLOADED_BEFORE_SEND":
|
||||
return PLATFORM_ERRORS.TRAFFIC_BUDGET_EXCEEDED;
|
||||
case "ABORTED_BY_SCOPE":
|
||||
return null;
|
||||
default:
|
||||
return PLATFORM_ERRORS.NETWORK_UNAVAILABLE;
|
||||
}
|
||||
case "CONTRACT_VIOLATION":
|
||||
switch (outcome.violation.kind) {
|
||||
case "RESPONSE_TOO_LARGE":
|
||||
return PLATFORM_ERRORS.RESPONSE_TOO_LARGE;
|
||||
case "SCOPE_FENCED":
|
||||
case "MISSING_IDEMPOTENCY_KEY":
|
||||
case "UNEXPECTED_IDEMPOTENCY_KEY":
|
||||
case "FINAL_REQUEST_INVARIANT_FAILED":
|
||||
return null;
|
||||
default:
|
||||
return PLATFORM_ERRORS.RESPONSE_INVALID;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user