From 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b Mon Sep 17 00:00:00 2001 From: Fuwn <50817549+Fuwn@users.noreply.github.com> Date: Sat, 24 Jan 2026 13:09:50 +0000 Subject: Initial commit Created from https://vercel.com/new --- src/lib/response.ts | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/lib/response.ts (limited to 'src/lib/response.ts') diff --git a/src/lib/response.ts b/src/lib/response.ts new file mode 100644 index 0000000..f1ad5c7 --- /dev/null +++ b/src/lib/response.ts @@ -0,0 +1,58 @@ +export function ok() { + return Response.json({ ok: true }); +} + +export function json(data: Record = {}) { + return Response.json(data); +} + +export function badRequest(error?: Record) { + return Response.json( + { + error: { message: 'Bad request', code: 'bad-request', status: 400, ...error }, + }, + { status: 400 }, + ); +} + +export function unauthorized(error?: Record) { + return Response.json( + { + error: { + message: 'Unauthorized', + code: 'unauthorized', + status: 401, + ...error, + }, + }, + { status: 401 }, + ); +} + +export function forbidden(error?: Record) { + return Response.json( + { error: { message: 'Forbidden', code: 'forbidden', status: 403, ...error } }, + { status: 403 }, + ); +} + +export function notFound(error?: Record) { + return Response.json( + { error: { message: 'Not found', code: 'not-found', status: 404, ...error } }, + { status: 404 }, + ); +} + +export function serverError(error?: Record) { + return Response.json( + { + error: { + message: 'Server error', + code: 'server-error', + status: 500, + ...error, + }, + }, + { status: 500 }, + ); +} -- cgit v1.2.3