Skip to content

SDK 内部 extractError 会屏蔽接口的错误信息,导致难以排错 #187

@nodejh

Description

@nodejh

lib/service_interface/json.js 里面的 extractError 方法会导致一些错误,无法展示给用户。

源码:

  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);
  },

而有的错误不是 codeCode,而是 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"}

这就导致了,该错误不会展示给用户,而是 SDK 抛出 UnknownError 异常。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions