@nxtedition/nxt-undici 2.0.44 → 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,37 +65,37 @@ 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
 
66
- const stackTraceLimit = Error.stackTraceLimit
67
- Error.stackTraceLimit = 0
68
- try {
69
- this.handler.onError(
70
- createHttpError(this.statusCode, {
71
- ureq: {
72
- origin: this.opts.origin,
73
- path: this.opts.path,
74
- method: this.opts.method,
75
- headers: this.opts.headers,
76
- },
77
- ures: { statusCode: this.statusCode, headers: this.headers, body: this.body },
78
- }),
79
- )
80
- } finally {
81
- Error.stackTraceLimit = stackTraceLimit
82
- }
80
+ err = createHttpError(this.statusCode)
83
81
 
84
82
  this.decoder = null
85
83
  this.contentType = null
86
84
  this.body = null
87
- } else if (err) {
88
- this.handler.onError(err)
85
+ }
86
+
87
+ if (err) {
88
+ this.handler.onError(
89
+ Object.assign(err, {
90
+ ureq: {
91
+ origin: this.opts.origin,
92
+ path: this.opts.path,
93
+ method: this.opts.method,
94
+ headers: this.opts.headers,
95
+ },
96
+ ures: { statusCode: this.statusCode, headers: this.headers, body: this.body },
97
+ }),
98
+ )
89
99
  } else {
90
100
  this.handler.onComplete(rawTrailers)
91
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "2.0.44",
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",