export async function getRequestBody( req: Request, validation?: (target: unknown) => target is T, ): Promise { if (req.body === null) { throw new Error("no body is present on the request"); } const body = await req.json(); if (validation && !validation(body)) { throw new Error("body validation failed"); } return body; }