Skip to content

Commit

Permalink
improved error propagation in RequestHandler - closes #747
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Aug 31, 2015
1 parent e38d751 commit 6586144
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions lib/utils/RequestHandler.js
Expand Up @@ -52,16 +52,7 @@ RequestHandler.prototype.setSessionID = function(body, response, data, fullReque
// check if we got a session id
/* istanbul ignore next */
if(!this.sessionID) {
this.eventHandler.emit('error', {
err: {
code: 'NOSESSIONID',
message: body.message
},
body: body,
requestOptions: fullRequestOptions,
response: response
});
throw new Error('NOSESSIONID');
throw new ErrorHandler.RuntimeError('A session id is required for this command but wasn\'t found in the response payload');
}

this.eventHandler.emit('init', {
Expand Down Expand Up @@ -151,14 +142,6 @@ RequestHandler.prototype.create = function(requestOptions, data) {

if(err || (body && body.status !== 0)) {

this.eventHandler.emit('error', {
err: err,
requestData: data,
requestOptions: fullRequestOptions,
response: response,
body: body
});

if(body && typeof body === 'string') {

error = new ErrorHandler.RuntimeError(body);
Expand Down Expand Up @@ -192,7 +175,11 @@ RequestHandler.prototype.create = function(requestOptions, data) {
// connected to a session itself and it therefore doesn't
// require it
if(this.sessionID === null && requestOptions.requiresSession !== false) {
this.setSessionID(body, response, data, fullRequestOptions);
try {
this.setSessionID(body, response, data, fullRequestOptions);
} catch(e) {
return defer.reject(e);
}
}

if(body === undefined) {
Expand Down

0 comments on commit 6586144

Please sign in to comment.