jpush-api-nodejs-client icon indicating copy to clipboard operation
jpush-api-nodejs-client copied to clipboard

Fail, HttpStatusCode: undefined result: [object Object]

Open lapidcj opened this issue 6 months ago • 0 comments

v4.2.0 使用JPush.js 的send(callback) 方式有问题,res不会携带statusCode, 所以一直会触发error,建议调整一下

Request2.js

resp.on('data', (res) => {
      if (res instanceof Buffer) {
        res = res.toString();
        if (resp.headers['content-type'].indexOf('application/json') > -1) res = JSON.parse(res);
      }
      if (client.isDebug) debug(res);
      resp.statusCode === 200 ? resolve(res) : reject(res);
      // 问题点:这里如果接口不返回statusCode,那么JPush.js中_request函数中的内置回调永远都会进入错误处理
      callback && callback(null, res, body);
    });

JPush.js

function _request (client, url, body, method, callback, times = 1) {
  ...
  var _callback = function (err, res, body) {
   ...
    if (res.statusCode === 200) {
      ...
    } else {
      if (client.isDebug) {
        debug('Fail, HttpStatusCode: ' + res.statusCode + ' result: ' + body.toString())
      }
      callback(new JError.APIRequestError(res.statusCode, body))
    }
  }
  Request2(client, url, { method, body: JSON.parse(body), timeout: client.readTimeOut }, _callback);
}

lapidcj avatar Jul 14 '25 08:07 lapidcj