Skip to content

Commit c764b61

Browse files
abetomoDeviaVir
authored andcommitted
Refactoring lib/schedule_events.js (#395)
* Use reject in schedule_events.js * Modify to omit parentheses in schedule_events.js
1 parent 112c2f6 commit c764b61

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/schedule_events.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class ScheduleEvents {
3333

3434
_putRule (params) {
3535
// return RuleArn if created
36-
return new Promise((resolve) => {
36+
return new Promise((resolve, reject) => {
3737
const _params = this._putRulePrams(params)
3838
this.cloudwatchevents.putRule(_params, (err, rule) => {
39-
if (err) throw err
39+
if (err) reject(err)
4040
resolve(rule)
4141
})
4242
})
@@ -53,11 +53,11 @@ class ScheduleEvents {
5353
}
5454

5555
_addPermission (params) {
56-
return new Promise((resolve) => {
56+
return new Promise((resolve, reject) => {
5757
const _params = this._addPermissionParams(params)
5858
this.lambda.addPermission(_params, (err, data) => {
5959
if (err) {
60-
if (err.code !== 'ResourceConflictException') throw err
60+
if (err.code !== 'ResourceConflictException') reject(err)
6161
// If it exists it will result in an error but there is no problem.
6262
resolve('Permission already set')
6363
}
@@ -78,11 +78,11 @@ class ScheduleEvents {
7878
}
7979

8080
_putTargets (params) {
81-
return new Promise((resolve) => {
81+
return new Promise((resolve, reject) => {
8282
const _params = this._putTargetsParams(params)
8383
this.cloudwatchevents.putTargets(_params, (err, data) => {
8484
// even if it is already registered, it will not be an error.
85-
if (err) throw (err)
85+
if (err) reject(err)
8686
resolve(data)
8787
})
8888
})
@@ -91,9 +91,9 @@ class ScheduleEvents {
9191
add (params) {
9292
return Promise.resolve().then(() => {
9393
return this._putRule(params)
94-
}).then((rule) => {
94+
}).then(rule => {
9595
return this._addPermission(Object.assign(params, rule))
96-
}).then((data) => {
96+
}).then(data => {
9797
return this._putTargets(params)
9898
})
9999
}

0 commit comments

Comments
 (0)