MCPcopy Index your code
hub / github.com/nodejs/node / _fetchJSON

Method _fetchJSON

lib/internal/debugger/inspect_client.js:268–301  ·  view source on GitHub ↗
(urlPath)

Source from the content-addressed store, hash-verified

266 }
267
268 _fetchJSON(urlPath) {
269 return new Promise((resolve, reject) => {
270 const httpReq = http.get({
271 host: this._host,
272 port: this._port,
273 path: urlPath,
274 });
275
276 const chunks = [];
277
278 function onResponse(httpRes) {
279 function parseChunks() {
280 const resBody = Buffer.concat(chunks).toString();
281 if (httpRes.statusCode !== 200) {
282 reject(new ERR_DEBUGGER_ERROR(`Unexpected ${httpRes.statusCode}: ${resBody}`));
283 return;
284 }
285 try {
286 resolve(JSONParse(resBody));
287 } catch {
288 reject(new ERR_DEBUGGER_ERROR(`Response didn't contain JSON: ${resBody}`));
289
290 }
291 }
292
293 httpRes.on('error', reject);
294 httpRes.on('data', (chunk) => ArrayPrototypePush(chunks, chunk));
295 httpRes.on('end', parseChunks);
296 }
297
298 httpReq.on('error', reject);
299 httpReq.on('response', onResponse);
300 });
301 }
302
303 async connect(port, host) {
304 this._port = port;

Callers 1

Calls 2

getMethod · 0.65
onMethod · 0.45

Tested by

no test coverage detected