@nxtedition/nxt-undici 4.2.19 → 4.2.20

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.
@@ -91,15 +91,41 @@ class Handler extends DecoratorHandler {
91
91
  }
92
92
 
93
93
  #decorateError(err) {
94
- return err
95
- // return Object.assign(err, {
96
- // url: new URL(this.#opts.path, this.#opts.origin).href,
97
- // headers: this.#headers,
98
- // reason: this.#body?.reason,
99
- // code: this.#body?.code,
100
- // error: this.#body?.error,
101
- // body: typeof this.#body !== 'string' || this.#body.length < 1024 ? this.#body : undefined,
102
- // })
94
+ try {
95
+ err.url ??= new URL(this.#opts.path, this.#opts.origin).href
96
+
97
+ err.req = {
98
+ method: this.#opts?.method,
99
+ headers: this.#opts?.headers,
100
+ body:
101
+ // TODO (fix): JSON.stringify POJO
102
+ typeof this.#opts?.body !== 'string' || this.#opts.body.length > 1024
103
+ ? undefined
104
+ : this.#opts.body,
105
+ }
106
+
107
+ err.res = {
108
+ headers: this.#headers,
109
+ // TODO (fix): JSON.stringify POJO
110
+ body: typeof this.#body !== 'string' || this.#body.length < 1024 ? undefined : this.#body,
111
+ }
112
+
113
+ if (this.#body) {
114
+ if (this.#body.reason != null) {
115
+ err.reason ??= this.#body.reason
116
+ }
117
+ if (this.#body.code != null) {
118
+ err.code ??= this.#body.code
119
+ }
120
+ if (this.#body.error != null) {
121
+ err.error ??= this.#body.errorq
122
+ }
123
+ }
124
+
125
+ return err
126
+ } catch {
127
+ return err
128
+ }
103
129
  }
104
130
  }
105
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "4.2.19",
3
+ "version": "4.2.20",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",