The public site answered every screen with the terminal error surface. Three defects stacked, and each one hid the next. The first refused the request outright: `attachCredentials` asks the Studio helper, which returns null for a profile it does not own, and the fallback below read the session and rejected anything not authenticated. Public reads declare the ANONYMOUS profile, so a signed-out visitor — the public site's entire audience — never got a request out of the browser. An anonymous profile carries no credentials by definition and must never consult the session. With requests flowing, the second surfaced: `envelopeError()` pinned `ApiError.code` to the Studio enum and all three surfaces shared it. Public and Management each declare their own enum in their own contract, so every error they returned failed validation and arrived as a CONTRACT_VIOLATION — an unclassifiable transport fault — rather than the domain error it was. A strict enum checked against the wrong surface's contract still looks strict, which is why no gate caught it. Each surface now passes its own contract's codes. The third was the not-found path: it read `status` and `code` off the problem body, but the envelope has no `status` and names the code for its surface (PUBLIC_RESOURCE_NOT_FOUND, not NOT_FOUND). The HTTP status from the transport is the authoritative signal and the only one that holds across both shapes. The regression test composes the real runtime adapters against the deployed backend's actual 404 body. Neither the gateway tests (which stub the executor) nor the screen tests (which stub the gateway) cover this seam, and the whole outage lived in it. Two page-level fixes came out of the same investigation: the profile page asked for two project slugs that only ever existed in the static fixture, and the index pages held their fixed header copy behind a request that had nothing to do with it. Headers now paint immediately; only the sections that are actually waiting show a fallback, and an empty list says so instead of rendering blank.
76 lines
3.1 KiB
TypeScript
76 lines
3.1 KiB
TypeScript
import type {
|
|
CreateDraftResponse,
|
|
ProjectEditResponse,
|
|
ProjectIndexPage,
|
|
ProjectUpdateRequest,
|
|
TopicEdit,
|
|
} from "../../contracts/management/contract.ts";
|
|
import type { ManagementGateway } from "../../application/ports/management-gateway.ts";
|
|
import type { StudioOperationExecutor } from "./http-studio-gateway.ts";
|
|
|
|
export type { ManagementGateway };
|
|
|
|
const ROUTE_ID = "TECH_LOG_STUDIO";
|
|
|
|
/**
|
|
* 주제·프로젝트 관리 게이트웨이.
|
|
*
|
|
* <p>Studio 게이트웨이와 같은 실패 규약을 쓴다 — 실패는 던지고, 화면은 `usePublicContent` 가 아니라
|
|
* Studio 쪽 상태 처리를 그대로 쓴다. 여기서 Result 로 감싸면 이 표면만 다른 규약이 된다.
|
|
*/
|
|
|
|
export class ManagementGatewayError extends Error {
|
|
readonly operationId: string;
|
|
readonly code: string;
|
|
|
|
constructor(operationId: string, code: string) {
|
|
super(`${operationId}: ${code}`);
|
|
this.name = "ManagementGatewayError";
|
|
this.operationId = operationId;
|
|
this.code = code;
|
|
}
|
|
}
|
|
|
|
export function createHttpManagementGateway(
|
|
deps: Readonly<{ operations: StudioOperationExecutor }>,
|
|
): ManagementGateway {
|
|
async function run<T>(operationId: string, input: unknown): Promise<T> {
|
|
const outcome = await deps.operations.execute(operationId, input, { routeId: ROUTE_ID });
|
|
if (outcome.kind === "SUCCESS") return outcome.value as T;
|
|
if (outcome.kind === "PROBLEM") {
|
|
// The management surface answers with the ADR-006 envelope, which nests
|
|
// the code under `error` — reading `problem.code` found nothing and every
|
|
// failure surfaced as the literal "PROBLEM", matching no i18n key.
|
|
const body = outcome.problem as
|
|
| Readonly<{ code?: unknown; error?: Readonly<{ code?: unknown }> }>
|
|
| null;
|
|
const code =
|
|
typeof body?.code === "string"
|
|
? body.code
|
|
: typeof body?.error?.code === "string"
|
|
? body.error.code
|
|
: "PROBLEM";
|
|
throw new ManagementGatewayError(operationId, code);
|
|
}
|
|
throw new ManagementGatewayError(operationId, outcome.kind);
|
|
}
|
|
|
|
return Object.freeze({
|
|
listTopics: () => run<TopicEdit[]>("listStudioTopics", {}),
|
|
createTopic: (input: TopicEdit) => run<TopicEdit>("createTopic", input),
|
|
updateTopic: (id: string, body: TopicEdit) => run<TopicEdit>("updateTopic", { id, body }),
|
|
deleteTopic: async (id: string, expectedVersion: number) => {
|
|
await run<void>("deleteTopic", { id, expectedVersion });
|
|
},
|
|
listProjects: (page?: number, size?: number) =>
|
|
run<ProjectIndexPage>("listStudioProjects", { ...(page !== undefined ? { page } : {}), ...(size !== undefined ? { size } : {}) }),
|
|
getProject: (id: string) => run<ProjectEditResponse>("getProjectForEdit", { id }),
|
|
createProject: (title: string) => run<CreateDraftResponse>("createProject", { title }),
|
|
updateProject: (id: string, body: ProjectUpdateRequest) =>
|
|
run<ProjectEditResponse>("updateProject", { id, body }),
|
|
deleteProject: async (id: string, expectedVersion: number) => {
|
|
await run<void>("deleteProject", { id, expectedVersion });
|
|
},
|
|
});
|
|
}
|