MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / parseJSONBody

Function parseJSONBody

src/api/httpUtils.ts:71–86  ·  view source on GitHub ↗
(req: HTTPRequestLike)

Source from the content-addressed store, hash-verified

69}
70
71export function parseJSONBody(req: HTTPRequestLike): Promise<Record<string, unknown>> {
72 return new Promise((resolve, reject) => {
73 let body = "";
74 req.on("data", (chunk: string | { toString(): string }) => {
75 body += chunk.toString();
76 });
77 req.on("end", () => {
78 try {
79 resolve(body ? JSON.parse(body) : {});
80 } catch {
81 reject(new Error("Invalid JSON"));
82 }
83 });
84 req.on("error", reject);
85 });
86}

Callers 2

parseBodyMethod · 0.90
parseRequestBodyFunction · 0.90

Calls 3

parseMethod · 0.80
onMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected