Skip to content

Commit

Permalink
understandable error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bajzarpa committed Jul 1, 2019
1 parent 3a91a39 commit da4e36a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"shx": "0.1.4"
},
"devDependencies": {
"colors": "^1.3.3",
"cross-env": "4.0.0",
"eslint": "3.15.0",
"eslint-config-semistandard": "7.0.0",
Expand Down
9 changes: 5 additions & 4 deletions src/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require('shelljs/global');
const shelljs = require('shelljs');
const request = require('request-promise');
require('colors');
const config = require('./config');
const uris = config.api.split(',').map(s => s + '/labels');

Expand All @@ -22,7 +23,7 @@ try {
}

if (!input.length) {
console.error('Payload is not an array?');
console.error('Payload is not an array?'.red.bold);
process.exit(1);
}

Expand All @@ -33,10 +34,10 @@ function upload (uri, count) {
const tfsId = String(body.TaskId || 0).replace(/[^\d]/g, '');
delete body.TaskId; // not yet implemented in the api
const environment = uri.split('.')[1];
console.log(`Uploading to ${environment}.... please wait!`);
console.log(`Uploading to ${environment}.... please wait!`.grey);
return request({method, uri, body, json: true, rejectUnauthorized: false, timeout: config.timeout})
.then((result) => {
console.log(`Uploaded to ${environment}: ${i + 1}. (out of ${l}) - Result: ${JSON.stringify(result)}`);
console.log(`Uploaded to ${environment}: ${i + 1}. (out of ${l}) - Result: ${JSON.stringify(result)}`.green.bold);
shelljs.config.silent = true;
mkdir(backupDir);
let target = `${backupDir}/${now}_#${tfsId}_${fileName}`;
Expand All @@ -46,7 +47,7 @@ function upload (uri, count) {
}
})
.catch(err => {
console.log(`Upload failed to ${environment}: ${i + 1}. [${id}] - Err: `, err);
console.log(`Upload failed to ${environment}: ${i + 1}. [${id}] - Err: ${err.response.statusCode}`.bold.red);
});
}
}
Expand Down

0 comments on commit da4e36a

Please sign in to comment.