Skip to content

Commit

Permalink
Merge pull request #144 from livehigh/fix/error-type
Browse files Browse the repository at this point in the history
fix:兼容错误类型
  • Loading branch information
carsonxu authored Apr 25, 2022
2 parents 30e9ffb + 7aa9610 commit 034d0fd
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions sdk/util.js
Original file line number Diff line number Diff line change
@@ -654,8 +654,21 @@ var error = function (err, opt) {

err.name = opt && opt.name || err.name || err.code || 'Error';
if (!err.code) err.code = err.name;
if (!err.error) err.error = clone(sourceErr); // 兼容老的错误格式


if (!err.error) {
var objectType = Object.prototype.toString.call(err);
if (objectType === '[object Object]') {
// 兼容老的错误格式
err.error = clone(sourceErr);
} else if (objectType === '[object Error]') {
// 有环境报出[object Error]对象的情况,兼容处理一下
err = {
code: err.code || err.name || 'Error',
name: err.name || err.code || 'Error',
message: err.reason || err.message || 'Error',
};
}
}
return err;
}

0 comments on commit 034d0fd

Please sign in to comment.