diff --git a/package-shared/functions/backend/httpRequest.js b/package-shared/functions/backend/httpRequest.js index 8e14819..d8d8c41 100644 --- a/package-shared/functions/backend/httpRequest.js +++ b/package-shared/functions/backend/httpRequest.js @@ -67,16 +67,29 @@ module.exports = function httpRequest(params) { }); response.on("end", function () { - try { - resolve(JSON.parse(str)); - } catch (/** @type {any} */ error) { - console.log("Route ERROR:", error.message); - resolve(null); - } + const data = (() => { + try { + /** @type {Object} */ + const jsonObj = JSON.parse(str); + return jsonObj; + } catch (error) { + return undefined; + } + })(); + + resolve({ + status: response.statusCode || 404, + data, + str, + }); }); response.on("error", (err) => { - resolve(null); + resolve({ + status: response.statusCode || 404, + str, + error: err.message, + }); }); } ); diff --git a/package-shared/types/index.d.ts b/package-shared/types/index.d.ts index 201fa8c..26a4ba1 100644 --- a/package-shared/types/index.d.ts +++ b/package-shared/types/index.d.ts @@ -1235,7 +1235,13 @@ export type HttpRequestParams = RequestOptions & { }; urlEncodedFormBody?: boolean; }; -export type HttpRequestFunctionType = (param: HttpRequestParams) => Promise<{ - [key: string]: any; -} | string | null>; +export type HttpRequestFunctionType = (param: HttpRequestParams) => Promise; +export type HttpFunctionResponse = { + status: number; + data?: { + [key: string]: any; + }; + error?: string; + str?: string; +}; export {}; diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index f60df71..050a880 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -1453,4 +1453,11 @@ export type HttpRequestParams = RequestOptions & { export type HttpRequestFunctionType = ( param: HttpRequestParams -) => Promise<{ [key: string]: any } | string | null>; +) => Promise; + +export type HttpFunctionResponse = { + status: number; + data?: { [key: string]: any }; + error?: string; + str?: string; +}; diff --git a/package.json b/package.json index 1848637..6ec020a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "3.3.4", + "version": "3.3.5", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": {