1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 },
);
}
|