alipay / alipay-sdk-nodejs-all

支付宝开放平台 Alipay SDK for Node.js
https://docs.open.alipay.com/54/103419/
Other
410 stars 65 forks source link

alipay.system.oauth.token未返回错误但抛出异常 #122

Closed keel closed 6 months ago

keel commented 6 months ago

const result = await alipaySdk.exec('alipay.system.oauth.token', { code: 'abcd', 'grant_type': 'authorization_code', });

执行以上代码时,result并不能正常接收到错误,而是抛出异常,这与其他接口返回错误的方式不一致,建议调整为返回错误。

抛出异常如下:

{ serverResult: { data: '{"error_response":{"msg":"Invalid Arguments","code":"40002","sub_msg":"授权码code无效","sub_code":"isv.code-invalid"},"sign":"Kkwr7JLayW+n/vKqeurTS85kuf5lXmEG8XajbQF4LOhAZ8RQc9Z8tCSuefZYM3VcREsOgdZ6hZGzEagBC/xWgzsrVpM6fQYqRKibqbjktpk9//YP4IRMpRUSAGYbP21+vuPfBldfg7aKm0LCKUIz731mzWnFWjNiWVQA1eysnyCs2x1jMILqKkobVq2ORTVXh381c3gT7qB4i0YejKZRyVo9VtKo3JhFbVvQ9vDRvPk/PCbbqO3Z1WcPvd87EpZ4/brkpD4c24yq07uDizxcr3qLgwKK8dyf2BRHPW+ybC7sCusnMRYaoIEWuD+B9m4gZpPAZuBJ0lWtt2WCI3qxpw=="}', status: 200, headers: { server: 'spanner/1.5.1', date: 'Mon, 20 May 2024 08:20:46 GMT', 'content-type': 'text/html;charset=utf-8', 'content-length': '477', connection: 'keep-alive', 'set-cookie': [Array], trace_id: 'xxxxxxxxx', invoke_id: 'XXXXXXX', via: 'spanner-internet-cz20m-57.ea179[200]', 'origin-agent-cluster': '?0' }, res: { status: 200, statusCode: 200, statusMessage: 'OK', headers: [Object], size: 477, aborted: false, rt: 223, keepAliveSocket: false, data: '{"error_response":{"msg":"Invalid Arguments","code":"40002","sub_msg":"授权码code无效","sub_code":"isv.code-invalid"},"sign":"Kkwr7JLayW+n/vKqeurTS85kuf5lXmEG8XajbQF4LOhAZ8RQc9Z8tCSuefZYM3VcREsOgdZ6hZGzEagBC/xWgzsrVpM6fQYqRKibqbjktpk9//YP4IRMpRUSAGYbP21+vuPfBldfg7aKm0LCKUIz731mzWnFWjNiWVQA1eysnyCs2x1jMILqKkobVq2ORTVXh381c3gT7qB4i0YejKZRyVo9VtKo3JhFbVvQ9vDRvPk/PCbbqO3Z1WcPvd87EpZ4/brkpD4c24yq07uDizxcr3qLgwKK8dyf2BRHPW+ybC7sCusnMRYaoIEWuD+B9m4gZpPAZuBJ0lWtt2WCI3qxpw=="}', requestUrls: [Array], timing: null, remoteAddress: '110.76.18.202', remotePort: 443, socketHandledRequests: 1, socketHandledResponses: 1 } }, errorMessage: '[AlipaySdk]HTTP 请求错误', traceId: 'xxxxxxxx' }

fengmk2 commented 6 months ago

https://github.com/alipay/alipay-sdk-nodejs-all/issues/120 正在重构最新版本,会按照支付宝 OPENAPI 最新规范返回。

fengmk2 commented 6 months ago

使用最新的 4.0.0 版本调用就会正确返回错误结构

const result = await alipaySdk.exec('alipay.system.oauth.token', {
  code: 'abcd', grant_type: 'authorization_code',
});
console.log(result);
{
  msg: 'Invalid Arguments',
  code: '40002',
  subMsg: '授权码code无效',
  subCode: 'isv.code-invalid',
  traceId: '06033316171731816251827584348'
}