index.js
function(call, error, response, body, codes, reject) {
	  if (error) {
		  if (typeof error == 'string') {
			  var message = util.format("Unexpected error on %s %s, reason : %s",
					   call.method, call.uri, error);
			  util.log(message);
			  var exception = new Error(message);
			  exception.call = call;
			  reject(exception);
		  } else {
			  util.log(error);
			  reject(error);
		  }
		  return true;
	  } else if (codes.indexOf(response.statusCode) <0 ) {
		  var message;
		  if (body.message){
			  message = util.format("Unexpected response code %s on %s %s, reason : %s",
					  response.statusCode, call.method, call.uri, body.message);
		  } else {
			  message = util.format("Unexpected response code %s on %s %s",
					  response.statusCode, call.method, call.uri);
		  }
		  util.log(message);
		  var exception = new Error(message);
		  exception.call = call;
		  exception.reason = body;
		  reject(exception);
		  return true;
	  }
	  return false;
}
function(call, error, response, body, codes, reject) {
	  if (error) {
		  if (typeof error == 'string') {
			  var message = util.format("Unexpected error on %s %s, reason : %s",
					   call.method, call.uri, error);
			  util.log(message);
			  var exception = new Error(message);
			  exception.call = call;
			  reject(exception);
		  } else {
			  util.log(error);
			  reject(error);
		  }
		  return true;
	  } else if (codes.indexOf(response.statusCode) <0 ) {
		  var message;
		  if (body.message){
			  message = util.format("Unexpected response code %s on %s %s, reason : %s",
					  response.statusCode, call.method, call.uri, body.message);
		  } else {
			  message = util.format("Unexpected response code %s on %s %s",
					  response.statusCode, call.method, call.uri);
		  }
		  util.log(message);
		  var exception = new Error(message);
		  exception.call = call;
		  exception.reason = body;
		  reject(exception);
		  return true;
	  }
	  return false;
}
function ( call , error , response , body , codes , reject ) { if ( error ) { if ( typeof error == 'string' ) { var message = util . format ( "Unexpected error on %s %s, reason : %s" , call . method , call . uri , error ) ; util . log ( message ) ; var exception = new Error ( message ) ; exception . call = call ; reject ( exception ) ; } else { util . log ( error ) ; reject ( error ) ; } return true ; } else if ( codes . indexOf ( response . statusCode ) < 0 ) { var message ; if ( body . message ) { message = util . format ( "Unexpected response code %s on %s %s, reason : %s" , response . statusCode , call . method , call . uri , body . message ) ; } else { message = util . format ( "Unexpected response code %s on %s %s" , response . statusCode , call . method , call . uri ) ; } util . log ( message ) ; var exception = new Error ( message ) ; exception . call = call ; exception . reason = body ; reject ( exception ) ; return true ; } return false ; }
Check for an error after calling an HTTP request.

@param call the call data
@param error the error info passed to the callback
@param response the HTTP response
@param body the HTTP body
@param codes the array of accepted response code
@param reject the promise reject call back to call in case of error
Check for an error after calling an HTTP request .