perf:增加rawResponse属性,返回原始的数据

This commit is contained in:
曾文豪
2023-06-06 09:45:06 +08:00
parent 1a5af5cdc9
commit 926909ed08
2 changed files with 14 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@tiesheng/npm-tool", "name": "@tiesheng/npm-tool",
"version": "1.0.11", "version": "1.0.12",
"description": "npm tool package", "description": "npm tool package",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -92,16 +92,20 @@ async function req(url, options) {
}, },
}) })
.then((res) => { .then((res) => {
if (res.code === 200) { if (options.rawResponse) {
let data = res.data; resolve(res);
if (res.encrypt) {
data = crypto.decrypt(data);
data = Common.parseJSON(data, data);
}
resolve({data, recordsTotal: res.recordsTotal})
} else { } else {
GlobalConfig.getConfig().onHttpError(res); if (res.code === 200) {
reject(res) let data = res.data;
if (res.encrypt) {
data = crypto.decrypt(data);
data = Common.parseJSON(data, data);
}
resolve({data, recordsTotal: res.recordsTotal})
} else {
GlobalConfig.getConfig().onHttpError(res);
reject(res)
}
} }
}) })
.catch((err) => { .catch((err) => {