Skip to content

Commit a2fa1a5

Browse files
committed
fix(commandline): error handling
deal with unhandled promise rejections
1 parent d5a613d commit a2fa1a5

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The command line modes and parameters map directly to the functions exposed for
7979
| ---- | ---------- |
8080
| getCustomRoles | none |
8181
| getCustomRole | customRoleKey |
82-
| createCustomRole | createCustomRole |
82+
| createCustomRole | customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription(optional) |
8383
| updateCustomRole | customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription(optional) |
8484
| upsertCustomRole | customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription(optional) |
8585
| bulkUpsertCustomRoles | roleBulkLoadFile |

ldutils

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ if (!process.env.LAUNCHDARKLY_API_TOKEN) {
1010
}
1111

1212
let log = console;
13+
14+
// fallback to bunyan logger if debug mode
1315
if (process.env.LAUNCHDARKLY_API_LOGLEVEL === 'debug') log = undefined;
16+
17+
process.on('unhandledRejection', (reason, p) => {
18+
console.error(json.plain({"error": reason}));
19+
process.exit(1);
20+
});
21+
1422
new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log).then(function(ldUtils) {
1523

1624
program
@@ -119,7 +127,6 @@ new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log).then(fun
119127
});
120128
});
121129

122-
console.log(process.argv);
123130
if (process.argv.length < 3) {
124131
program.help();
125132
process.exit(1);
@@ -128,8 +135,5 @@ new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log).then(fun
128135
program
129136
.parse(process.argv);
130137

131-
})
132-
.catch(function(e) {
133-
console.log(json.plain(e));
134138
});
135139

src/LaunchDarklyUtilsRoles.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ export class LaunchDarklyUtilsRoles {
1818
}
1919

2020
async getCustomRole(customRoleKey) {
21-
let that = this;
22-
return this.apiClient.apis[this.API_GROUP]
23-
.getCustomRole({
24-
customRoleKey: customRoleKey
25-
})
26-
.catch(e => {
27-
that.log.error(e);
28-
throw e;
29-
});
21+
return this.apiClient.apis[this.API_GROUP].getCustomRole({ customRoleKey: customRoleKey });
3022
}
3123

3224
async createCustomRole(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) {

0 commit comments

Comments
 (0)