({ callback, body, contentType, statusCode, statusMessage, headers })
| 56284 | // node_modules/undici/lib/api/util.js |
| 56285 | var require_util4 = __commonJS({ |
| 56286 | "node_modules/undici/lib/api/util.js"(exports2, module2) { |
| 56287 | var assert2 = require("assert"); |
| 56288 | var { |
| 56289 | ResponseStatusCodeError |
| 56290 | } = require_errors3(); |
| 56291 | var { toUSVString } = require_util2(); |
| 56292 | async function getResolveErrorBodyCallback({ callback, body, contentType, statusCode, statusMessage, headers }) { |
| 56293 | assert2(body); |
| 56294 | let chunks = []; |
| 56295 | let limit = 0; |
| 56296 | for await (const chunk of body) { |
| 56297 | chunks.push(chunk); |
| 56298 | limit += chunk.length; |
| 56299 | if (limit > 128 * 1024) { |
| 56300 | chunks = null; |
| 56301 | break; |
| 56302 | } |
| 56303 | } |
| 56304 | if (statusCode === 204 || !contentType || !chunks) { |
| 56305 | process.nextTick(callback, new ResponseStatusCodeError(`Response status code ${statusCode}${statusMessage ? `: ${statusMessage}` : ""}`, statusCode, headers)); |
| 56306 | return; |
| 56307 | } |
| 56308 | try { |
| 56309 | if (contentType.startsWith("application/json")) { |
| 56310 | const payload = JSON.parse(toUSVString(Buffer.concat(chunks))); |
| 56311 | process.nextTick(callback, new ResponseStatusCodeError(`Response status code ${statusCode}${statusMessage ? `: ${statusMessage}` : ""}`, statusCode, headers, payload)); |
| 56312 | return; |
| 56313 | } |
| 56314 | if (contentType.startsWith("text/")) { |
| 56315 | const payload = toUSVString(Buffer.concat(chunks)); |
| 56316 | process.nextTick(callback, new ResponseStatusCodeError(`Response status code ${statusCode}${statusMessage ? `: ${statusMessage}` : ""}`, statusCode, headers, payload)); |
| 56317 | return; |
| 56318 | } |
| 56319 | } catch (err) { |
nothing calls this directly
no test coverage detected