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
+30
View File
@@ -0,0 +1,30 @@
import "server-only";
import { NextResponse } from "next/server";
import { DomainError } from "../domain/errors";
export function apiSuccess<T>(data: T, init?: ResponseInit): NextResponse {
return NextResponse.json({ ok: true, data }, init);
}
export function apiError(error: unknown): NextResponse {
if (error instanceof DomainError) {
return NextResponse.json(
{
ok: false,
error: {
code: error.code,
message: error.message,
...(error.details ? { details: error.details } : {}),
},
},
{ status: error.status },
);
}
console.error("Unhandled API error", error);
return NextResponse.json(
{ ok: false, error: { code: "INTERNAL_ERROR", message: "Beklenmeyen bir sunucu hatası oluştu." } },
{ status: 500 },
);
}