@nxtedition/lib 14.0.26 → 14.1.0
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/errors.js +2 -2
- package/package.json +4 -3
- package/undici.js +29 -0
package/errors.js
CHANGED
|
@@ -122,9 +122,9 @@ module.exports.makeMessages = function makeMessages(error, options) {
|
|
|
122
122
|
} else if (error) {
|
|
123
123
|
let err
|
|
124
124
|
if (typeof error === 'string' && error) {
|
|
125
|
-
err = { msg: error, id: options?.id, level: options?.level ||
|
|
125
|
+
err = { msg: error, id: options?.id, level: options?.level || 50, code: options?.code }
|
|
126
126
|
} else if (typeof error === 'object') {
|
|
127
|
-
const level = parseInt(error.level) || options?.level ||
|
|
127
|
+
const level = parseInt(error.level) || options?.level || 50
|
|
128
128
|
const code =
|
|
129
129
|
[error?.code, options?.codes?.[error?.code]].find(
|
|
130
130
|
(x) => typeof x === 'string' && x.length > 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "14.0
|
|
3
|
+
"version": "14.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"files": [
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"errors.js",
|
|
24
24
|
"worker.js",
|
|
25
25
|
"proxy.js",
|
|
26
|
+
"undici.js",
|
|
26
27
|
"timeline.js",
|
|
27
28
|
"docker-secrets.js"
|
|
28
29
|
],
|
|
@@ -72,7 +73,6 @@
|
|
|
72
73
|
"date-fns": "^2.29.3",
|
|
73
74
|
"fast-querystring": "^1.1.1",
|
|
74
75
|
"hasha": "^5.2.2",
|
|
75
|
-
"http-errors": "^2.0.0",
|
|
76
76
|
"json5": "^2.2.3",
|
|
77
77
|
"koa-compose": "^4.1.0",
|
|
78
78
|
"lodash": "^4.17.21",
|
|
@@ -88,7 +88,8 @@
|
|
|
88
88
|
"split-string": "^6.0.0",
|
|
89
89
|
"toobusy-js": "^0.5.1",
|
|
90
90
|
"undici": "^5.22.0",
|
|
91
|
-
"url-join": "^4.0.0"
|
|
91
|
+
"url-join": "^4.0.0",
|
|
92
|
+
"xuid": "^4.1.2"
|
|
92
93
|
},
|
|
93
94
|
"devDependencies": {
|
|
94
95
|
"eslint": "^8.38.0",
|
package/undici.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as undici from 'undici'
|
|
2
|
+
import xuid from 'xuid'
|
|
3
|
+
|
|
4
|
+
export async function request(url, { logger, ...options }) {
|
|
5
|
+
const ureq = {
|
|
6
|
+
url,
|
|
7
|
+
maxRedirections: 3,
|
|
8
|
+
headers: {
|
|
9
|
+
'req-id': xuid(),
|
|
10
|
+
'user-agent': options.userAgent,
|
|
11
|
+
...options.headers,
|
|
12
|
+
},
|
|
13
|
+
...options,
|
|
14
|
+
throwOnError: true,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
logger?.debug({ ureq }, 'upstream request started')
|
|
18
|
+
|
|
19
|
+
const ures = await undici.request(url, options)
|
|
20
|
+
|
|
21
|
+
logger?.debug({ ureq, ures }, 'upstream request response')
|
|
22
|
+
|
|
23
|
+
if (ures.statusCode >= 300 && ures.statusCode < 400) {
|
|
24
|
+
await ures.body.dump()
|
|
25
|
+
throw new Error('maxRedirections exceeded')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return ures
|
|
29
|
+
}
|