@nxtedition/nxt-undici 2.0.45 → 2.0.46

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.
@@ -2,17 +2,27 @@ import { findHeader, parseHeaders } from '../utils.js'
2
2
  import createHttpError from 'http-errors'
3
3
 
4
4
  class Handler {
5
+ handler
6
+ opts
7
+
8
+ statusCode
9
+ contentType
10
+ decoder
11
+ headers
12
+ body
13
+
5
14
  constructor(opts, { handler }) {
6
15
  this.handler = handler
16
+ this.opts = opts
17
+ }
18
+
19
+ onConnect(abort) {
7
20
  this.statusCode = 0
8
21
  this.contentType = null
9
22
  this.decoder = null
10
23
  this.headers = null
11
24
  this.body = null
12
- this.opts = opts
13
- }
14
25
 
15
- onConnect(abort) {
16
26
  return this.handler.onConnect(abort)
17
27
  }
18
28
 
@@ -55,16 +65,28 @@ class Handler {
55
65
  }
56
66
 
57
67
  onFinally(err, rawTrailers) {
58
- if (this.statusCode) {
68
+ if (this.statusCode >= 400) {
59
69
  if (this.decoder != null) {
60
70
  this.body += this.decoder.decode(undefined, { stream: false })
61
71
  if (this.contentType === 'application/json') {
62
- this.body = JSON.parse(this.body)
72
+ try {
73
+ this.body = JSON.parse(this.body)
74
+ } catch {
75
+ // Do nothing...
76
+ }
63
77
  }
64
78
  }
65
79
 
80
+ err = createHttpError(this.statusCode)
81
+
82
+ this.decoder = null
83
+ this.contentType = null
84
+ this.body = null
85
+ }
86
+
87
+ if (err) {
66
88
  this.handler.onError(
67
- createHttpError(this.statusCode, {
89
+ Object.assign(err, {
68
90
  ureq: {
69
91
  origin: this.opts.origin,
70
92
  path: this.opts.path,
@@ -74,12 +96,6 @@ class Handler {
74
96
  ures: { statusCode: this.statusCode, headers: this.headers, body: this.body },
75
97
  }),
76
98
  )
77
-
78
- this.decoder = null
79
- this.contentType = null
80
- this.body = null
81
- } else if (err) {
82
- this.handler.onError(err)
83
99
  } else {
84
100
  this.handler.onComplete(rawTrailers)
85
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "2.0.45",
3
+ "version": "2.0.46",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",
@@ -12,22 +12,22 @@
12
12
  "cache-control-parser": "^2.0.5",
13
13
  "cacheable-lookup": "^7.0.0",
14
14
  "http-errors": "^2.0.0",
15
- "lru-cache": "^10.1.0",
16
- "undici": "^6.1.0"
15
+ "lru-cache": "^10.2.0",
16
+ "undici": "^6.13.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@types/node": "^20.10.5",
20
- "eslint": "^8.56.0",
19
+ "@types/node": "^20.12.7",
20
+ "eslint": "^8.0.0",
21
21
  "eslint-config-prettier": "^9.1.0",
22
22
  "eslint-config-standard": "^17.0.0",
23
23
  "eslint-plugin-import": "^2.29.1",
24
- "eslint-plugin-n": "^16.5.0",
24
+ "eslint-plugin-n": "^17.2.0",
25
25
  "eslint-plugin-promise": "^6.1.1",
26
- "husky": "^8.0.3",
27
- "lint-staged": "^15.2.0",
26
+ "husky": "^9.0.11",
27
+ "lint-staged": "^15.2.2",
28
28
  "pinst": "^3.0.0",
29
- "prettier": "^3.1.1",
30
- "tap": "^18.6.1"
29
+ "prettier": "^3.2.5",
30
+ "tap": "^18.7.2"
31
31
  },
32
32
  "scripts": {
33
33
  "prepare": "husky install",