@hzab/data-model
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "@hzab/data-model", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "data model", | ||
@@ -5,0 +5,0 @@ "main": "src", |
import _ from "lodash"; | ||
import axios from "axios"; | ||
const _$Temp = {}; | ||
const DEFAULT_MSG = "未知错误"; | ||
const _$Temp = { | ||
defaultMsg: DEFAULT_MSG, | ||
}; | ||
@@ -284,12 +287,13 @@ class DataModel { | ||
// 前缀 _ 避免与 data 里已有的 message 冲突 | ||
_data._message = message || msg; | ||
_data._msg = message || msg; | ||
_data._message = _data._msg; | ||
} | ||
resolve(_data); | ||
} else { | ||
const error = new Error(message || msg); | ||
const _msg = message || msg || _$Temp.defaultMsg; | ||
const error = new Error(_msg); | ||
error.code = code; | ||
error.response = response; | ||
error._message = message || msg; | ||
error._msg = message || msg; | ||
error._msg = _msg; | ||
error._message = _msg; | ||
reject(error); | ||
@@ -302,4 +306,8 @@ } | ||
if (response) { | ||
const message = (response.data && (response.data.message || response.data.msg)) || response.msg; | ||
const error = new Error(message || response.statusText || "未知错误"); | ||
const message = | ||
(response.data && (response.data.message || response.data.msg)) || | ||
response.msg || | ||
response.statusText || | ||
_$Temp.defaultMsg; | ||
const error = new Error(message); | ||
error.code = response.status; | ||
@@ -314,3 +322,3 @@ error.response = response; | ||
} | ||
return reject(err); | ||
return reject(err || { _msg: _$Temp.defaultMsg }); | ||
} | ||
@@ -325,4 +333,10 @@ } | ||
export function setDefaultErrMsg(msg) { | ||
if (msg) { | ||
_$Temp.defaultMsg = msg; | ||
} | ||
} | ||
export { axios, DataModel, setDefaultAxios }; | ||
export default DataModel; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15680
429