-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
getJob.js
40 lines (37 loc) · 1.31 KB
/
getJob.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const colors = require('colors');
const request = require('./request');
const getJob = (opt, jobId, cb) => {
request(opt.apiPath + '/jobs/' + opt.projectId + '/' + jobId, {
method: 'get',
headers: {
'Authorization': opt.apiKey
}
}, (err, res, obj) => {
if (err || (obj && (obj.errorMessage || obj.message))) {
if (!cb) console.log(colors.red('getting job failed...'));
if (err) {
if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
if (cb) cb(err);
return;
}
if (obj && (obj.errorMessage || obj.message)) {
if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
if (cb) cb(new Error((obj.errorMessage || obj.message)));
return;
}
}
if (res.status === 404) {
if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
if (cb) cb(null, null);
return;
}
if (res.status >= 300) {
if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
return;
}
if (!cb) console.log(colors.green('getting job succesfull'));
if (cb) cb(null, obj);
});
};
module.exports = getJob;