Update http request function
This commit is contained in:
parent
e28cf872ea
commit
4bda9149c6
@ -67,16 +67,29 @@ module.exports = function httpRequest(params) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
response.on("end", function () {
|
response.on("end", function () {
|
||||||
try {
|
const data = (() => {
|
||||||
resolve(JSON.parse(str));
|
try {
|
||||||
} catch (/** @type {any} */ error) {
|
/** @type {Object<string,any>} */
|
||||||
console.log("Route ERROR:", error.message);
|
const jsonObj = JSON.parse(str);
|
||||||
resolve(null);
|
return jsonObj;
|
||||||
}
|
} catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
status: response.statusCode || 404,
|
||||||
|
data,
|
||||||
|
str,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
response.on("error", (err) => {
|
response.on("error", (err) => {
|
||||||
resolve(null);
|
resolve({
|
||||||
|
status: response.statusCode || 404,
|
||||||
|
str,
|
||||||
|
error: err.message,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
12
package-shared/types/index.d.ts
vendored
12
package-shared/types/index.d.ts
vendored
@ -1235,7 +1235,13 @@ export type HttpRequestParams = RequestOptions & {
|
|||||||
};
|
};
|
||||||
urlEncodedFormBody?: boolean;
|
urlEncodedFormBody?: boolean;
|
||||||
};
|
};
|
||||||
export type HttpRequestFunctionType = (param: HttpRequestParams) => Promise<{
|
export type HttpRequestFunctionType = (param: HttpRequestParams) => Promise<HttpFunctionResponse>;
|
||||||
[key: string]: any;
|
export type HttpFunctionResponse = {
|
||||||
} | string | null>;
|
status: number;
|
||||||
|
data?: {
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
|
error?: string;
|
||||||
|
str?: string;
|
||||||
|
};
|
||||||
export {};
|
export {};
|
||||||
|
@ -1453,4 +1453,11 @@ export type HttpRequestParams = RequestOptions & {
|
|||||||
|
|
||||||
export type HttpRequestFunctionType = (
|
export type HttpRequestFunctionType = (
|
||||||
param: HttpRequestParams
|
param: HttpRequestParams
|
||||||
) => Promise<{ [key: string]: any } | string | null>;
|
) => Promise<HttpFunctionResponse>;
|
||||||
|
|
||||||
|
export type HttpFunctionResponse = {
|
||||||
|
status: number;
|
||||||
|
data?: { [key: string]: any };
|
||||||
|
error?: string;
|
||||||
|
str?: string;
|
||||||
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "3.3.4",
|
"version": "3.3.5",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user