moul / node-gitlab

DEPRECATED, see https://github.com/node-gitlab/node-gitlab
https://npmjs.org/package/gitlab
Other
470 stars 140 forks source link

Parsed JSON gets parsed #149

Closed jacob418 closed 5 years ago

jacob418 commented 8 years ago

lib\ApiBaseHTTP.js:88:42

undefined:1
[object Object]
 ^

SyntaxError: Unexpected token o
    at Object.parse (native)
    at C:\Users\fricke\Documents\senseit\transferGitlabLabels\node_modules\gitlab\lib\ApiBaseHTTP.js:88:42
    at _Class.wrap_response (C:\Users\fricke\Documents\senseit\transferGitlabLabels\node_modules\gitlab\node_modules\slumber\lib\API.js:192:18)
    at _Class.wrap_response (C:\Users\fricke\Documents\senseit\transferGitlabLabels\node_modules\gitlab\node_modules\slumber\lib\API.js:4:59)
    at Request._callback (C:\Users\fricke\Documents\senseit\transferGitlabLabels\node_modules\gitlab\node_modules\slumber\lib\API.js:215:26)
    at Request.self.callback (C:\Users\fricke\Documents\senseit\transferGitlabLabels\node_modules\gitlab\node_modules\slumber\node_modules\request\request.js:187:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (C:\Users\fricke\Documents\senseit\transferGitlabLabels\node_modules\gitlab\node_modules\slumber\node_modules\request\request.js:1048:10)
    at emitOne (events.js:77:13)

When debugging this code, i recogniced, that in


    ApiBaseHTTP.prototype.fn_wrapper = function(fn) {
      return (function(_this) {
        return function(err, response, ret) {
          var arity;
          arity = fn.length;
          switch (arity) {
            case 1:
              return fn(ret);
            case 2:
              return fn(err, ret || JSON.parse(response.body).message);
            case 3:
              return fn(err, response, ret);
          }
        };
      })(this);
    };

the response.body is already parsed, resulting in an error, when trying to parse.

AlexBarbulescu commented 8 years ago

Any fix for this?

MJochim commented 7 years ago

Is this as easy as to replace https://github.com/node-gitlab/node-gitlab/blob/2e547cb94ba8dfa3d6c648f9526083fd2e65ccc4/lib/ApiBaseHTTP.js#L88 with return fn(err, ret || response.body.message);

Seems like the obvious choice but I am not familiar with the codebase.