@vulog/aima-client 1.0.10 → 1.0.11

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/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @vulog/aima-client
2
2
 
3
+ ```bash
4
+ npm i @vulog/aima-client
5
+ ```
6
+
3
7
  ```javascript
4
8
  import { getClient } from '@vulog/aima-client';
5
9
 
package/dist/index.d.mts CHANGED
@@ -16,8 +16,9 @@ type ClientOptions = {
16
16
  };
17
17
  type ClientError = {
18
18
  formattedError: {
19
- status: number;
20
- data: any;
19
+ status?: number;
20
+ data?: any;
21
+ message?: string;
21
22
  };
22
23
  originalError: any;
23
24
  };
package/dist/index.d.ts CHANGED
@@ -16,8 +16,9 @@ type ClientOptions = {
16
16
  };
17
17
  type ClientError = {
18
18
  formattedError: {
19
- status: number;
20
- data: any;
19
+ status?: number;
20
+ data?: any;
21
+ message?: string;
21
22
  };
22
23
  originalError: any;
23
24
  };
package/dist/index.js CHANGED
@@ -115,13 +115,19 @@ var CurlHelper = class {
115
115
  // src/getClient.ts
116
116
  var clientCache = new import_lru_cache.LRUCache({ max: 100 });
117
117
  var formatError = (error) => {
118
- const { response: { status, data } = { status: 500 } } = error ?? {};
118
+ if (error instanceof import_axios.AxiosError) {
119
+ return {
120
+ originalError: error.toJSON(),
121
+ formattedError: {
122
+ status: error.response?.status ?? error.status,
123
+ data: error.response?.data,
124
+ message: error.message
125
+ }
126
+ };
127
+ }
119
128
  return {
120
- formattedError: {
121
- status,
122
- data
123
- },
124
- originalError: error.toJSON ? error.toJSON() : error
129
+ formattedError: {},
130
+ originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
125
131
  };
126
132
  };
127
133
  var getClient = (options) => {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/getClient.ts
2
- import axios from "axios";
2
+ import axios, { AxiosError } from "axios";
3
3
  import _ from "lodash";
4
4
  import { LRUCache } from "lru-cache";
5
5
 
@@ -79,13 +79,19 @@ var CurlHelper = class {
79
79
  // src/getClient.ts
80
80
  var clientCache = new LRUCache({ max: 100 });
81
81
  var formatError = (error) => {
82
- const { response: { status, data } = { status: 500 } } = error ?? {};
82
+ if (error instanceof AxiosError) {
83
+ return {
84
+ originalError: error.toJSON(),
85
+ formattedError: {
86
+ status: error.response?.status ?? error.status,
87
+ data: error.response?.data,
88
+ message: error.message
89
+ }
90
+ };
91
+ }
83
92
  return {
84
- formattedError: {
85
- status,
86
- data
87
- },
88
- originalError: error.toJSON ? error.toJSON() : error
93
+ formattedError: {},
94
+ originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
89
95
  };
90
96
  };
91
97
  var getClient = (options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-client",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
package/src/getClient.ts CHANGED
@@ -1,4 +1,4 @@
1
- import axios from 'axios';
1
+ import axios, { AxiosError } from 'axios';
2
2
  import _ from 'lodash';
3
3
  import { LRUCache } from 'lru-cache';
4
4
 
@@ -14,14 +14,20 @@ const clientCache = new LRUCache<
14
14
  >({ max: 100 });
15
15
 
16
16
  const formatError = (error: any): ClientError => {
17
- const { response: { status, data } = { status: 500 } } = error ?? {};
17
+ if (error instanceof AxiosError) {
18
+ return {
19
+ originalError: error.toJSON(),
20
+ formattedError: {
21
+ status: error.response?.status ?? error.status,
22
+ data: error.response?.data,
23
+ message: error.message,
24
+ },
25
+ };
26
+ }
18
27
 
19
28
  return {
20
- formattedError: {
21
- status,
22
- data,
23
- },
24
- originalError: error.toJSON ? error.toJSON() : error,
29
+ formattedError: {},
30
+ originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))),
25
31
  };
26
32
  };
27
33
 
package/src/types.ts CHANGED
@@ -17,8 +17,9 @@ export type ClientOptions = {
17
17
 
18
18
  export type ClientError = {
19
19
  formattedError: {
20
- status: number;
21
- data: any;
20
+ status?: number;
21
+ data?: any;
22
+ message?: string;
22
23
  };
23
24
  originalError: any;
24
25
  };