node-consul-service 1.0.20 → 1.0.22

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.
@@ -6,5 +6,11 @@ interface CallServiceOptions {
6
6
  headers?: AxiosRequestHeaders;
7
7
  params?: Record<string, any>;
8
8
  }
9
- export declare function callService(serviceName: string, options?: CallServiceOptions): Promise<any>;
9
+ interface ServiceResponse<T = any> {
10
+ success: boolean;
11
+ data?: T;
12
+ message?: string;
13
+ status?: number;
14
+ }
15
+ export declare function callService(serviceName: string, options?: CallServiceOptions): Promise<ServiceResponse>;
10
16
  export {};
package/dist/index.cjs.js CHANGED
@@ -19400,17 +19400,33 @@ const {
19400
19400
  } = axios;
19401
19401
 
19402
19402
  async function callService(serviceName, options = {}) {
19403
+ var _a, _b;
19403
19404
  const { method = 'GET', path = '/hello', data, headers, params, } = options;
19404
- const instance = await getRandomServiceInstance(serviceName);
19405
- const url = `http://${instance.ServiceAddress}:${instance.ServicePort}${path}`;
19406
- const response = await axios.request({
19407
- url,
19408
- method,
19409
- data,
19410
- headers,
19411
- params,
19412
- });
19413
- return response.data;
19405
+ try {
19406
+ const instance = await getRandomServiceInstance(serviceName);
19407
+ const url = `http://${instance.ServiceAddress}:${instance.ServicePort}${path}`;
19408
+ const response = await axios.request({
19409
+ url,
19410
+ method,
19411
+ data,
19412
+ headers,
19413
+ params,
19414
+ });
19415
+ return {
19416
+ success: true,
19417
+ data: response.data,
19418
+ status: response.status,
19419
+ };
19420
+ }
19421
+ catch (error) {
19422
+ console.log("🚀 ~ error:", error);
19423
+ return {
19424
+ success: false,
19425
+ message: error.message,
19426
+ status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
19427
+ data: (_b = error.response) === null || _b === void 0 ? void 0 : _b.data,
19428
+ };
19429
+ }
19414
19430
  }
19415
19431
 
19416
19432
  async function dataLink(data, schema) {
package/dist/index.esm.js CHANGED
@@ -19398,17 +19398,33 @@ const {
19398
19398
  } = axios;
19399
19399
 
19400
19400
  async function callService(serviceName, options = {}) {
19401
+ var _a, _b;
19401
19402
  const { method = 'GET', path = '/hello', data, headers, params, } = options;
19402
- const instance = await getRandomServiceInstance(serviceName);
19403
- const url = `http://${instance.ServiceAddress}:${instance.ServicePort}${path}`;
19404
- const response = await axios.request({
19405
- url,
19406
- method,
19407
- data,
19408
- headers,
19409
- params,
19410
- });
19411
- return response.data;
19403
+ try {
19404
+ const instance = await getRandomServiceInstance(serviceName);
19405
+ const url = `http://${instance.ServiceAddress}:${instance.ServicePort}${path}`;
19406
+ const response = await axios.request({
19407
+ url,
19408
+ method,
19409
+ data,
19410
+ headers,
19411
+ params,
19412
+ });
19413
+ return {
19414
+ success: true,
19415
+ data: response.data,
19416
+ status: response.status,
19417
+ };
19418
+ }
19419
+ catch (error) {
19420
+ console.log("🚀 ~ error:", error);
19421
+ return {
19422
+ success: false,
19423
+ message: error.message,
19424
+ status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
19425
+ data: (_b = error.response) === null || _b === void 0 ? void 0 : _b.data,
19426
+ };
19427
+ }
19412
19428
  }
19413
19429
 
19414
19430
  async function dataLink(data, schema) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",