@nxtedition/nxt-undici 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +5 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -332,10 +332,11 @@ export async function request(url, opts) {
|
|
|
332
332
|
await res.dump()
|
|
333
333
|
} else if (res.statusCode >= 400) {
|
|
334
334
|
// TODO (fix): Limit the size of the body?
|
|
335
|
-
const data =
|
|
336
|
-
res.
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
const data = /^application\/json$/i.test(res.headers['content-type'])
|
|
336
|
+
? await res.json()
|
|
337
|
+
: /^text-.+/i.test(res.headers['content-type'])
|
|
338
|
+
? await res.text()
|
|
339
|
+
: await res.dump()
|
|
339
340
|
throw createError(res.statusCode, { headers, data })
|
|
340
341
|
}
|
|
341
342
|
|