Skip to content

Commit

Permalink
fix: translate TCP errors
Browse files Browse the repository at this point in the history
fixes #129
  • Loading branch information
rahulreddy committed Feb 1, 2017
1 parent ccb74f8 commit 5c1a260
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 10 additions & 8 deletions lib/IAMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const http = require('http');
const https = require('https');
const parseString = require('xml2js').parseString;
const queryString = require('querystring');
const Logger = require('werelogs').Logger;

class IAMClient {
/**
Expand Down Expand Up @@ -52,6 +53,7 @@ class IAMClient {
}
this.accessKey = accessKey;
this.secretKeyValue = secretKeyValue;
this.logger = new Logger('vaultclient');
}

getServerHost() {
Expand Down Expand Up @@ -423,9 +425,8 @@ class IAMClient {
method: 'IAMClient:request()',
error: err.stack || err,
});
return callback(errors.InternalError);
}
return callback(err);
return callback(errors.InternalError);
});
req.end();
}
Expand Down Expand Up @@ -481,10 +482,11 @@ class IAMClient {
* @returns {undefined}
*/
handleResponse(res, ret, log, callback) {
const logger = log || this.logger;
this.getObj(ret, (err, obj) => {
if (err) {
if (log) {
log.error('error from vault',
if (logger) {
logger.error('error from vault',
{ error: err, method: 'IAMClient.handleResponse' });
}
return callback(err, null, res.statusCode);
Expand All @@ -496,15 +498,15 @@ class IAMClient {

// Load the error from errors(arsenal)
if (obj && obj.ErrorResponse && obj.ErrorResponse.Error) {
if (log) {
log.debug('error from vault',
if (logger) {
logger.debug('error from vault',
{ error: obj, method: 'IAMClient.handleResponse' });
}
return callback(
errors[obj.ErrorResponse.Error.Code], null, res.statusCode);
}
if (log) {
log.error('unable to translate error from vault', {
if (logger) {
logger.error('unable to translate error from vault', {
error: obj,
method: 'IAMClient.handleResponse',
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dependencies": {
"arsenal": "scality/Arsenal#rel/6.2.5",
"commander": "^2.9.0",
"xml2js": "^0.4.16"
"xml2js": "^0.4.16",
"werelogs": "scality/werelogs#rel/6.2.5"
},
"devDependencies": {
"babel-eslint": "^4.1.3",
Expand Down

0 comments on commit 5c1a260

Please sign in to comment.