diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/lib/response.ts | |
| download | umami-main.tar.xz umami-main.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/lib/response.ts')
| -rw-r--r-- | src/lib/response.ts | 58 |
1 files changed, 58 insertions, 0 deletions
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<string, any> = {}) { + return Response.json(data); +} + +export function badRequest(error?: Record<string, any>) { + return Response.json( + { + error: { message: 'Bad request', code: 'bad-request', status: 400, ...error }, + }, + { status: 400 }, + ); +} + +export function unauthorized(error?: Record<string, any>) { + return Response.json( + { + error: { + message: 'Unauthorized', + code: 'unauthorized', + status: 401, + ...error, + }, + }, + { status: 401 }, + ); +} + +export function forbidden(error?: Record<string, any>) { + return Response.json( + { error: { message: 'Forbidden', code: 'forbidden', status: 403, ...error } }, + { status: 403 }, + ); +} + +export function notFound(error?: Record<string, any>) { + return Response.json( + { error: { message: 'Not found', code: 'not-found', status: 404, ...error } }, + { status: 404 }, + ); +} + +export function serverError(error?: Record<string, any>) { + return Response.json( + { + error: { + message: 'Server error', + code: 'server-error', + status: 500, + ...error, + }, + }, + { status: 500 }, + ); +} |