@@ -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