@nxtedition/lib 18.0.6 → 18.0.8

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.
Files changed (2) hide show
  1. package/couch.js +12 -3
  2. package/package.json +1 -1
package/couch.js CHANGED
@@ -245,7 +245,6 @@ export function makeCouch(opts) {
245
245
  'request-id': genReqId(),
246
246
  ...(body ? { 'content-type': 'application/json' } : {}),
247
247
  },
248
- throwOnError: true,
249
248
  highWaterMark: 256 * 1024, // TODO (fix): Needs support in undici...
250
249
  bodyTimeout: 2 * (params.heartbeat || 60e3),
251
250
  }
@@ -253,6 +252,14 @@ export function makeCouch(opts) {
253
252
  try {
254
253
  const res = await client.request(req)
255
254
 
255
+ if (res.statusCode < 200 || res.statusCode >= 300) {
256
+ throw makeError(req, {
257
+ status: res.statusCode,
258
+ headers: res.headers,
259
+ data: await res.body.text(),
260
+ })
261
+ }
262
+
256
263
  retryCount = 0
257
264
 
258
265
  let str = ''
@@ -304,6 +311,7 @@ export function makeCouch(opts) {
304
311
  idempotent: true,
305
312
  blocking: live,
306
313
  method,
314
+ maxRedirects: 4,
307
315
  body: JSON.stringify(body),
308
316
  signal: ac.signal,
309
317
  headers: {
@@ -327,7 +335,7 @@ export function makeCouch(opts) {
327
335
  return await res.body.json()
328
336
  } catch (err) {
329
337
  Object.assign(err, { data: req })
330
- return { err }
338
+ throw err
331
339
  }
332
340
  }
333
341
 
@@ -355,7 +363,7 @@ export function makeCouch(opts) {
355
363
  return
356
364
  }
357
365
 
358
- promise = next()
366
+ promise = next().catch((err) => ({ err }))
359
367
 
360
368
  if (batched) {
361
369
  yield results
@@ -375,6 +383,7 @@ export function makeCouch(opts) {
375
383
  }
376
384
  return
377
385
  } catch (err) {
386
+ err.reason ??= err.body?.reason
378
387
  if (err.name === 'AbortError' || client.destroyed) {
379
388
  throw err
380
389
  } else if (typeof retry === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "18.0.6",
3
+ "version": "18.0.8",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",