import { Observable } from "rxjs/Observable" ; export function retry ( times = 3 , fallback ) { return ( target , key , descriptor ) => { const originalMethod = descriptor . value ; descriptor . value = function ( ) { return originalMethod . apply ( this ) . retryWhen ( ( errors ) => { return errors . scan ( ( errorCount , err ) => { console . log ( 'Try ' + ( errorCount + 1 ) ) ; if ( errorCount >= times - 1 ) { throw err ; } return errorCount + 1 ; } , 0 ) . delay ( 1000 ) ; } ) . catch ( ( ) => Observable . of ( fallback ) ) ; } ; return descriptor ; } ; }