Closed saraf closed 9 years ago
Superagent already parses JSON into objects for us
superagent is parsing the JSON received from the API into Objects per - https://visionmedia.github.io/superagent/#parsing-response%20bodies, so in webapp.js, branches does not contain a JSON/string but an Object. JSON.parse(branches) is failing with Unexpected token o JSON.parse is perhaps not required - when getting a list of projects and also when getting a list of branches. With the code as it stands, we crash when trying to configure a project.
2015-08-05T05:05:48.543Z - error: strider-gitlab:webapp Getting URI projects/2/repository/branches +0ms
2015-08-05T05:05:48.573Z - error: strider-gitlab:api Response body type: object +0ms
undefined:1
[object Object]
^
SyntaxError: Unexpected token o
at Object.parse (native)
at /home/dev/sandbox/strider/node_modules/strider-gitlab/lib/webapp.js:68:23
at /home/dev/sandbox/strider/node_modules/strider-gitlab/lib/api.js:50:7
at Request.callback (/home/dev/sandbox/strider/node_modules/strider-gitlab/node_modules/superagent/lib/node/index.js:628:30)
at Request.
Released as 1.1.1
When there was a problem in the gitlab configuration and an unreachable/incorrect hostname was specified, instead of JSON, we were getting undefined from the get method in api.js, and we were crashing.
Added an error message for this case so that we do not crash.
Ideally we should be checking for a valid reachable gitlab host when saving the configuration.
Crash trace below:
SyntaxError: Unexpected token u at Object.parse (native) at /home/dev/sandbox/strider/node_modules/strider-gitlab/lib/webapp.js:34:20 at /home/dev/sandbox/strider/node_modules/strider-gitlab/lib/api.js:45:16 at Request.callback (/home/dev/sandbox/strider/node_modules/strider-gitlab/node_modules/superagent/lib/node/index.js:628:30) at ClientRequest. (/home/dev/sandbox/strider/node_modules/strider-gitlab/node_modules/superagent/lib/node/index.js:596:10)
at ClientRequest.emit (events.js:107:17)
at Socket.socketErrorListener (_http_client.js:271:9)
at Socket.emit (events.js:107:17)
at net.js:459:14
at process._tickCallback (node.js:355:11)
9284 died 1 null