Custom readValidatedBody util to return more specific error #69 (#78)

* feat: add readDropValidatedBody w/ special handler for ArkErrors

* fix: lint
This commit is contained in:
DecDuck
2025-06-03 17:40:41 +10:00
committed by GitHub
parent f264fd0971
commit 4f8ea3e4ff
11 changed files with 43 additions and 19 deletions

View File

@ -2,7 +2,7 @@ import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import objectHandler from "~/server/internal/objects";
import { type } from "arktype";
import { throwingArktype } from "~/server/arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
const DeleteGameImage = type({
gameId: "string",
@ -15,7 +15,7 @@ export default defineEventHandler<{
const allowed = await aclManager.allowSystemACL(h3, ["game:image:delete"]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readValidatedBody(h3, DeleteGameImage);
const body = await readDropValidatedBody(h3, DeleteGameImage);
const gameId = body.gameId;
const imageId = body.imageId;

View File

@ -1,5 +1,5 @@
import { type } from "arktype";
import { throwingArktype } from "~/server/arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
@ -15,7 +15,7 @@ export default defineEventHandler<{ body: typeof DeleteVersion }>(
]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readValidatedBody(h3, DeleteVersion);
const body = await readDropValidatedBody(h3, DeleteVersion);
const gameId = body.id.toString();
const version = body.versionName.toString();

View File

@ -1,5 +1,5 @@
import { type } from "arktype";
import { throwingArktype } from "~/server/arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
@ -15,7 +15,7 @@ export default defineEventHandler<{ body: typeof UpdateVersionOrder }>(
]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readValidatedBody(h3, UpdateVersionOrder);
const body = await readDropValidatedBody(h3, UpdateVersionOrder);
const gameId = body.id;
// We expect an array of the version names for this game
const versions = body.versions;