mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Fixed error messages.
This commit is contained in:
parent
e7163c4e7e
commit
a3fb27a0db
3 changed files with 13790 additions and 18 deletions
|
|
@ -10,7 +10,8 @@
|
||||||
"url": "https://github.com/umami-software/umami.git"
|
"url": "https://github.com/umami-software/umami.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 3000 --turbo",
|
"dev": "next dev -p 3000",
|
||||||
|
"dev-turbo": "next dev -p 3000 --turbo",
|
||||||
"build": "npm-run-all check-env build-db check-db build-tracker build-geo build-app",
|
"build": "npm-run-all check-env build-db check-db build-tracker build-geo build-app",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"build-docker": "npm-run-all build-db build-tracker build-geo build-app",
|
"build-docker": "npm-run-all build-db build-tracker build-geo build-app",
|
||||||
|
|
|
||||||
13770
pnpm-lock.yaml
generated
Normal file
13770
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -5,14 +5,6 @@ import { getAllowedUnits, getMinimumUnit } from '@/lib/date';
|
||||||
import { checkAuth } from '@/lib/auth';
|
import { checkAuth } from '@/lib/auth';
|
||||||
import { getWebsiteDateRange } from '@/queries';
|
import { getWebsiteDateRange } from '@/queries';
|
||||||
|
|
||||||
export async function getJsonBody(request: Request) {
|
|
||||||
try {
|
|
||||||
return await request.clone().json();
|
|
||||||
} catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function parseRequest(
|
export async function parseRequest(
|
||||||
request: Request,
|
request: Request,
|
||||||
schema?: ZodSchema,
|
schema?: ZodSchema,
|
||||||
|
|
@ -24,15 +16,6 @@ export async function parseRequest(
|
||||||
let error: () => void | undefined;
|
let error: () => void | undefined;
|
||||||
let auth = null;
|
let auth = null;
|
||||||
|
|
||||||
const getErrorMessages = (error: z.ZodError) => {
|
|
||||||
return Object.entries(error.format())
|
|
||||||
.map(([key, value]) => {
|
|
||||||
const messages = (value as any)._errors;
|
|
||||||
return messages ? `${key}: ${messages.join(', ')}` : null;
|
|
||||||
})
|
|
||||||
.filter(Boolean);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (schema) {
|
if (schema) {
|
||||||
const isGet = request.method === 'GET';
|
const isGet = request.method === 'GET';
|
||||||
const result = schema.safeParse(isGet ? query : body);
|
const result = schema.safeParse(isGet ? query : body);
|
||||||
|
|
@ -57,6 +40,14 @@ export async function parseRequest(
|
||||||
return { url, query, body, auth, error };
|
return { url, query, body, auth, error };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getJsonBody(request: Request) {
|
||||||
|
try {
|
||||||
|
return await request.clone().json();
|
||||||
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getRequestDateRange(query: Record<string, any>) {
|
export async function getRequestDateRange(query: Record<string, any>) {
|
||||||
const { websiteId, startAt, endAt, unit } = query;
|
const { websiteId, startAt, endAt, unit } = query;
|
||||||
|
|
||||||
|
|
@ -96,3 +87,13 @@ export function getRequestFilters(query: Record<string, any>) {
|
||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getErrorMessages(error: z.ZodError) {
|
||||||
|
return Object.entries(error.format())
|
||||||
|
.flatMap(([key, value]) => {
|
||||||
|
if (key === '_errors') {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue