MCPcopy
hub / github.com/lissy93/web-check / parseBody

Function parseBody

api/_common/http.js:33–45  ·  view source on GitHub ↗
(response)

Source from the content-addressed store, hash-verified

31
32// Auto-parse JSON when the response advertises it, fall back to raw text
33const parseBody = async (response) => {
34 const ct = (response.headers.get('content-type') || '').toLowerCase();
35 const text = await response.text();
36 if (!text) return ct.includes('json') ? null : '';
37 if (ct.includes('json')) {
38 try {
39 return JSON.parse(text);
40 } catch {
41 return text;
42 }
43 }
44 return text;
45};
46
47const isOk = (status, validate) => (validate ? validate(status) : status >= 200 && status < 300);
48

Callers 1

sendFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected