Strider-CD / strider-gitlab

Seamless integration between Strider and GitLab
25 stars 16 forks source link

Crash on receiving bad data when listing projects #24

Closed saraf closed 9 years ago

saraf commented 9 years ago

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

saraf commented 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. (/home/dev/sandbox/strider/node_modules/strider-gitlab/node_modules/superagent/lib/node/index.js:131:10) at Request.emit (events.js:107:17) at Stream. (/home/dev/sandbox/strider/node_modules/strider-gitlab/node_modules/superagent/lib/node/index.js:773:12) at Stream.emit (events.js:129:20) at Unzip. (/home/dev/sandbox/strider/node_modules/strider-gitlab/node_modules/superagent/lib/node/utils.js:124:12) at Unzip.emit (events.js:129:20) at _stream_readable.js:908:16 at process._tickCallback (node.js:355:11)

knownasilya commented 9 years ago

Released as 1.1.1