I want to read the body of a request in my hooks.server.ts import type { Handle } from '@sveltejs/kit';
export const handle = (async ({ event, resolve }) => {
console.log(event.request.body);
const response = await resolve(event);
return response;
}) satisfies Handle;
This gives me
ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
If i read it
const reader = request.body.getReader();
let text;
let result;
while (!(result = await reader.read()).done) {
text += result.value;
}
console.log(text);
console.log(request.body);
And then log the body, i get:
ReadableStream { locked: true, state: 'closed', supportsBYOB: false }
This leads to the actuall call I want to do to thrown an error
TypeError: Body is unusable at specConsumeBody (/home/hp/git/booking/node_modules/undici/lib/fetch/body.js:492:11) at Request.json (/home/hp/git/booking/node_modules/undici/lib/fetch/body.js:359:14)
How can I read the body in hooks?