Fixed error messages.

This commit is contained in:
Mike Cao 2025-03-19 23:52:44 -07:00
parent e7163c4e7e
commit a3fb27a0db
3 changed files with 13790 additions and 18 deletions

View file

@ -10,7 +10,8 @@
"url": "https://github.com/umami-software/umami.git"
},
"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",
"start": "next start",
"build-docker": "npm-run-all build-db build-tracker build-geo build-app",

13770
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -5,14 +5,6 @@ import { getAllowedUnits, getMinimumUnit } from '@/lib/date';
import { checkAuth } from '@/lib/auth';
import { getWebsiteDateRange } from '@/queries';
export async function getJsonBody(request: Request) {
try {
return await request.clone().json();
} catch {
return undefined;
}
}
export async function parseRequest(
request: Request,
schema?: ZodSchema,
@ -24,15 +16,6 @@ export async function parseRequest(
let error: () => void | undefined;
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) {
const isGet = request.method === 'GET';
const result = schema.safeParse(isGet ? query : body);
@ -57,6 +40,14 @@ export async function parseRequest(
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>) {
const { websiteId, startAt, endAt, unit } = query;
@ -96,3 +87,13 @@ export function getRequestFilters(query: Record<string, any>) {
return obj;
}, {});
}
export function getErrorMessages(error: z.ZodError) {
return Object.entries(error.format())
.flatMap(([key, value]) => {
if (key === '_errors') {
return value;
}
})
.filter(Boolean);
}