extractError: function extractError(resp) {
var error = {};
var httpResponse = resp.httpResponse;
if (httpResponse.body.length > 0) {
var e = JSON.parse(httpResponse.body.toString());
if (e.__type || e.code || e.Code) {
error.code = (e.__type || e.code || e.Code).split('#').pop();
} else {
error.code = 'UnknownError';
}
if (error.code === 'RequestEntityTooLarge') {
error.message = 'Request body must be less than 1 MB';
} else {
error.message = (e.message || e.Message || null);
}
} else {
error.code = httpResponse.statusCode;
error.message = null;
}
resp.error = ALY.util.error(new Error(), error);
},
而有的错误不是 code 或 Code,而是 errorCode,如 SLS 接口的错误:
{"errorCode":"ParameterInvalid","errorMessage":"ErrorType:ColumnNotExists.ErrorPosition,line:1633886764,column:1.ErrorMessage:line 1:109: Column 'count' cannot be resolved;please add the column in the index attribute"}
lib/service_interface/json.js
里面的extractError
方法会导致一些错误,无法展示给用户。源码:
而有的错误不是
code
或Code
,而是errorCode
,如 SLS 接口的错误:这就导致了,该错误不会展示给用户,而是 SDK 抛出
UnknownError
异常。