mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Consistent error responses. Updated login page.
This commit is contained in:
parent
88f2ac20bc
commit
4c24e54fdd
17 changed files with 170 additions and 159 deletions
|
|
@ -1,5 +1,3 @@
|
|||
import { serializeError } from 'serialize-error';
|
||||
|
||||
export function ok() {
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
|
|
@ -8,22 +6,53 @@ export function json(data: any) {
|
|||
return Response.json(data);
|
||||
}
|
||||
|
||||
export function badRequest(error: any = 'Bad request') {
|
||||
return Response.json({ error: serializeError(error) }, { status: 400 });
|
||||
export function badRequest(error?: any) {
|
||||
return Response.json(
|
||||
{
|
||||
error: { message: 'Bad request', code: 'bad-request', status: 400, ...error },
|
||||
},
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
export function unauthorized(error: any = 'Unauthorized') {
|
||||
return Response.json({ error: serializeError(error) }, { status: 401 });
|
||||
export function unauthorized(error?: any) {
|
||||
return Response.json(
|
||||
{
|
||||
error: {
|
||||
message: 'Unauthorized',
|
||||
code: 'unauthorized',
|
||||
status: 401,
|
||||
...error,
|
||||
},
|
||||
},
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
export function forbidden(error: any = 'Forbidden') {
|
||||
return Response.json({ error: serializeError(error) }, { status: 403 });
|
||||
export function forbidden(error?: any) {
|
||||
return Response.json(
|
||||
{ error: { message: 'Forbidden', code: 'forbidden', status: 403, ...error } },
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
|
||||
export function notFound(error: any = 'Not found') {
|
||||
return Response.json({ error: serializeError(error) }, { status: 404 });
|
||||
export function notFound(error?: any) {
|
||||
return Response.json(
|
||||
{ error: { message: 'Not found', code: 'not-found', status: 404, ...error } },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
|
||||
export function serverError(error: any = 'Server error') {
|
||||
return Response.json({ error: serializeError(error) }, { status: 500 });
|
||||
export function serverError(error?: any) {
|
||||
return Response.json(
|
||||
{
|
||||
error: {
|
||||
message: 'Server error',
|
||||
code: 'server-error',
|
||||
status: 500,
|
||||
...error,
|
||||
},
|
||||
},
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue