@exode-team/multicard-uz.api 1.0.1 → 1.0.2
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/PROMPT.md +84 -0
- package/dist/multicard-api.js +13 -2
- package/package.json +1 -1
package/PROMPT.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Fix: requestApi error handling — circular structure to JSON
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
|
|
5
|
+
In `src/multicard-api.ts`, the `requestApi` method re-throws the raw Axios error:
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
} catch (error) {
|
|
9
|
+
console.error(...);
|
|
10
|
+
throw error; // Raw Axios error with circular refs!
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Axios error objects contain `error.request` (ClientRequest) and `error.response.req` (IncomingMessage) which form a circular reference: `ClientRequest.res → IncomingMessage.req → ClientRequest`.
|
|
15
|
+
|
|
16
|
+
When this error bubbles up to Apollo Server (GraphQL), it tries to `JSON.stringify` the error → **"Converting circular structure to JSON"**.
|
|
17
|
+
|
|
18
|
+
## Fix
|
|
19
|
+
|
|
20
|
+
In `src/multicard-api.ts`, change the `catch` block in `requestApi` to return a `MulticardErrorResponse` instead of throwing:
|
|
21
|
+
|
|
22
|
+
**From:**
|
|
23
|
+
```typescript
|
|
24
|
+
} catch (error) {
|
|
25
|
+
const response = (error as any)?.response;
|
|
26
|
+
|
|
27
|
+
console.error(
|
|
28
|
+
'[PACKAGE:multicard-uz.api]',
|
|
29
|
+
`status=${response?.status}`,
|
|
30
|
+
`config=[${JSON.stringify(config)}]`,
|
|
31
|
+
JSON.stringify(response?.data),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**To:**
|
|
39
|
+
```typescript
|
|
40
|
+
} catch (error) {
|
|
41
|
+
const response = (error as any)?.response;
|
|
42
|
+
|
|
43
|
+
console.error(
|
|
44
|
+
'[PACKAGE:multicard-uz.api]',
|
|
45
|
+
`status=${response?.status}`,
|
|
46
|
+
`config=[${JSON.stringify(config)}]`,
|
|
47
|
+
JSON.stringify(response?.data),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
error: {
|
|
53
|
+
code: MulticardErrorCode.ERROR_UNKNOWN,
|
|
54
|
+
details: response?.data?.message
|
|
55
|
+
|| response?.data?.error?.details
|
|
56
|
+
|| (error as Error).message
|
|
57
|
+
|| 'Unknown error',
|
|
58
|
+
},
|
|
59
|
+
} as T;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Also add `MulticardErrorCode` to the imports at the top of the file:
|
|
64
|
+
```typescript
|
|
65
|
+
import {
|
|
66
|
+
// ... existing imports
|
|
67
|
+
MulticardErrorCode,
|
|
68
|
+
// ...
|
|
69
|
+
} from './types';
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Why
|
|
73
|
+
|
|
74
|
+
- All Multicard provider methods already check `response.success` before using `response.data`
|
|
75
|
+
- Returning `{ success: false, error: {...} }` lets the consumer handle errors gracefully
|
|
76
|
+
- No circular references in the error object
|
|
77
|
+
- Consistent with the `MulticardResponse` type contract
|
|
78
|
+
|
|
79
|
+
## After fix
|
|
80
|
+
|
|
81
|
+
Bump version to `1.0.2`, build and publish:
|
|
82
|
+
```bash
|
|
83
|
+
npm version patch && yarn build && npm publish
|
|
84
|
+
```
|
package/dist/multicard-api.js
CHANGED
|
@@ -21,7 +21,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
21
21
|
if (v !== undefined) module.exports = v;
|
|
22
22
|
}
|
|
23
23
|
else if (typeof define === "function" && define.amd) {
|
|
24
|
-
define(["require", "exports", "axios", "./multicard-base"], factory);
|
|
24
|
+
define(["require", "exports", "axios", "./multicard-base", "./types"], factory);
|
|
25
25
|
}
|
|
26
26
|
})(function (require, exports) {
|
|
27
27
|
"use strict";
|
|
@@ -29,6 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
exports.MulticardApi = void 0;
|
|
30
30
|
const axios_1 = __importDefault(require("axios"));
|
|
31
31
|
const multicard_base_1 = require("./multicard-base");
|
|
32
|
+
const types_1 = require("./types");
|
|
32
33
|
class MulticardApi extends multicard_base_1.MulticardBase {
|
|
33
34
|
/**
|
|
34
35
|
* Запрос к API
|
|
@@ -41,6 +42,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
42
|
*/
|
|
42
43
|
requestApi(apiUrl_1) {
|
|
43
44
|
return __awaiter(this, arguments, void 0, function* (apiUrl, data = {}, headers, httpMethod = 'post') {
|
|
45
|
+
var _a, _b, _c;
|
|
44
46
|
const config = {
|
|
45
47
|
timeout: this.timeoutMs,
|
|
46
48
|
url: `${this.baseUrl}${apiUrl}`,
|
|
@@ -60,7 +62,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
60
62
|
catch (error) {
|
|
61
63
|
const response = error === null || error === void 0 ? void 0 : error.response;
|
|
62
64
|
console.error('[PACKAGE:multicard-uz.api]', `status=${response === null || response === void 0 ? void 0 : response.status}`, `config=[${JSON.stringify(config)}]`, JSON.stringify(response === null || response === void 0 ? void 0 : response.data));
|
|
63
|
-
|
|
65
|
+
return {
|
|
66
|
+
success: false,
|
|
67
|
+
error: {
|
|
68
|
+
code: types_1.MulticardErrorCode.ERROR_UNKNOWN,
|
|
69
|
+
details: ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.message)
|
|
70
|
+
|| ((_c = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.details)
|
|
71
|
+
|| error.message
|
|
72
|
+
|| 'Unknown error',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
64
75
|
}
|
|
65
76
|
});
|
|
66
77
|
}
|