blob: a178009b561ce12086f7a19544fb3127dde90842 [file] [log] [blame]
Adrià Vilanova Martínez9c418ab2024-12-05 15:34:40 +01001export default class FetchBody {
2 constructor(private body: RequestInit['body'] | undefined) {}
3
4 async getJSONRequestBody() {
5 if (!this.body) return undefined;
6
7 // Using Response is a hack, but it works and converts a possibly long code
8 // into a one-liner :D
9 // Source of inspiration: https://stackoverflow.com/a/72718732
10 return await new Response(this.body).json();
11 }
12}