@faasjs/request 1.3.1 → 1.4.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/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -51,7 +51,8 @@ var ResponseError = class extends Error {
|
|
|
51
51
|
};
|
|
52
52
|
async function request(url$1, options = { headers: {} }) {
|
|
53
53
|
var _a;
|
|
54
|
-
const
|
|
54
|
+
const requestId = crypto.randomUUID();
|
|
55
|
+
const logger$1 = options.logger || new logger.Logger(`request][${requestId}`);
|
|
55
56
|
if (mock) {
|
|
56
57
|
logger$1.debug("mock %s %j", url$1, options);
|
|
57
58
|
return mock(url$1, options);
|
|
@@ -94,7 +95,6 @@ async function request(url$1, options = { headers: {} }) {
|
|
|
94
95
|
body = JSON.stringify(body);
|
|
95
96
|
if (body && !options.headers["Content-Length"])
|
|
96
97
|
requestOptions.headers["Content-Length"] = Buffer.byteLength(body);
|
|
97
|
-
const requestId = crypto.randomUUID();
|
|
98
98
|
return await new Promise((resolve, reject) => {
|
|
99
99
|
logger$1.debug("request %j", {
|
|
100
100
|
...options,
|
|
@@ -168,7 +168,7 @@ async function request(url$1, options = { headers: {} }) {
|
|
|
168
168
|
response.statusMessage = res.statusMessage;
|
|
169
169
|
response.headers = res.headers;
|
|
170
170
|
response.body = data;
|
|
171
|
-
if (response.body && response.headers["content-type"] && response.headers["content-type"].includes("application/json"))
|
|
171
|
+
if (response.body && response.headers["content-type"] && response.headers["content-type"].includes("application/json") && typeof response.body === "string" && (response.body.startsWith("{") || response.body.startsWith("[")))
|
|
172
172
|
try {
|
|
173
173
|
response.body = (options.parse || JSON.parse)(response.body);
|
|
174
174
|
logger$1.debug("response.parse JSON");
|
package/dist/index.mjs
CHANGED
|
@@ -44,7 +44,8 @@ var ResponseError = class extends Error {
|
|
|
44
44
|
};
|
|
45
45
|
async function request(url, options = { headers: {} }) {
|
|
46
46
|
var _a;
|
|
47
|
-
const
|
|
47
|
+
const requestId = randomUUID();
|
|
48
|
+
const logger = options.logger || new Logger(`request][${requestId}`);
|
|
48
49
|
if (mock) {
|
|
49
50
|
logger.debug("mock %s %j", url, options);
|
|
50
51
|
return mock(url, options);
|
|
@@ -87,7 +88,6 @@ async function request(url, options = { headers: {} }) {
|
|
|
87
88
|
body = JSON.stringify(body);
|
|
88
89
|
if (body && !options.headers["Content-Length"])
|
|
89
90
|
requestOptions.headers["Content-Length"] = Buffer.byteLength(body);
|
|
90
|
-
const requestId = randomUUID();
|
|
91
91
|
return await new Promise((resolve, reject) => {
|
|
92
92
|
logger.debug("request %j", {
|
|
93
93
|
...options,
|
|
@@ -161,7 +161,7 @@ async function request(url, options = { headers: {} }) {
|
|
|
161
161
|
response.statusMessage = res.statusMessage;
|
|
162
162
|
response.headers = res.headers;
|
|
163
163
|
response.body = data;
|
|
164
|
-
if (response.body && response.headers["content-type"] && response.headers["content-type"].includes("application/json"))
|
|
164
|
+
if (response.body && response.headers["content-type"] && response.headers["content-type"].includes("application/json") && typeof response.body === "string" && (response.body.startsWith("{") || response.body.startsWith("[")))
|
|
165
165
|
try {
|
|
166
166
|
response.body = (options.parse || JSON.parse)(response.body);
|
|
167
167
|
logger.debug("response.parse JSON");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/request",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@faasjs/logger": "1.
|
|
24
|
+
"@faasjs/logger": "1.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@faasjs/logger": "1.
|
|
27
|
+
"@faasjs/logger": "1.4.0"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"npm": ">=9.0.0",
|