Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix throw response exception #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DiscoverForever
Copy link

问题:当请求京东联盟API返回异常,目前是包装了{code: xx, message: 'xxx' }作为正常返回给了SDK使用者。是否需要把异常作为Promise.reject明确返回给用户?
建议:给用户抛出异常。
修改前使用SDK

let res = await client.execute('jd.union.open.order.query', {
  orderReq: {
    pageNo: 1,
    pageSize: 20,
    type: 1,
    time: '20200217160303'
  }
})
if (res.code === 0) {
  ...
} else {
  ...
}

修改后使用SDK

try {
   let res = await client.execute('jd.union.open.order.query', {
       orderReq: {
         pageNo: 1,
         pageSize: 20,
         type: 1,
         time: '20200217160303'
     }
   })
} catch (error) {
  // 处理异常
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant