yhtx 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/index.js +31 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -62,15 +62,42 @@ async function call(path, { apiKey, secret, data, method, recvWindow } = {}) {
62
62
  ...(method == "POST" && { data }), //must be "data" //if GET, don't send
63
63
  };
64
64
 
65
+ // let r = await axios(config)
66
+ // .then((r) => {
67
+ // if (!(r.data?.code == 200 /*success*/ || r.data?.status == "ok"))
68
+ // console.log(r.data); //if not code:200 or status:ok, then log
69
+ // let rs = r.data.data;
70
+ // return rs;
71
+ // })
72
+ // .catch(function (e) {
73
+ // console.log(e.response.data);
74
+ // }); //old
65
75
  let r = await axios(config)
66
76
  .then((r) => {
67
- if (!(r.data?.code == 200 /*success*/ || r.data?.status == "ok"))
68
- console.log(r.data); //if not code:200 or status:ok, then log
77
+ let dt = r.data;
78
+ if (dt?.code == 403 && msg == "Verification failure [校验失败]") {
79
+ console.log("api issue: null"); //{code:403,msg:'Verification failure [校验失败]',data:null,ts:1758849372250}
80
+ } else if (dt?.status == "error" && dt?.["err-code"] == "api-signature-not-valid") {
81
+ console.log("api issue2: null"); ////{status: 'error','err-code': 'api-signature-not-valid','err-msg': 'Signature not valid: Verification failure [校验失败]',data:null}
82
+ } else if (dt?.message == "Verification failure [校验失败]" && dt?.code == 1003) {
83
+ console.log("api issue3: undefined"); //{ message: 'Verification failure [校验失败]', code: 1003, success: false }
84
+ } else if (dt?.message == "Verification failure" && dt?.code == 12008) {
85
+ console.log("api issue4: null"); //{ code: 12008, message: "Verification failure", data: null };
86
+ } else if (!(r.data?.code == 200 /*success*/ || r.data?.status == "ok")) {
87
+ console.log(r.data); //if not code:200 or status:ok, then log //
88
+ } //eg{message:'The account API interface queried is empty',code:40237,success:false}
89
+
69
90
  let rs = r.data.data;
70
- return rs;
91
+ if (rs == null && dt?.status == "error") {
92
+ rs = r.data; //eg rs={status:"error","err-code":"dw-withdraw-precision-limit","err-msg":"withdraw amount precision cannot be greater than 6",data:null}
93
+ } else if (rs == undefined && dt?.success == false && dt?.code != 1003) {
94
+ rs = r.data; //eg rs={message:'The account API interface queried is empty',code:40237,success:false}
95
+ }
96
+
97
+ return rs; //rs=DATA | {status:'error','err=code','err-msg',data:null} | null(if api fail) | undefined(if apiFail)
71
98
  })
72
99
  .catch(function (e) {
73
- console.log(e.response.data);
100
+ console.log(e.response?.data);
74
101
  });
75
102
 
76
103
  return r;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yhtx",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "HTX API",
5
5
  "main": "index.js",
6
6
  "scripts": {