constructor(fb:FormBuilder) {
        this.formModel = fb.group({
            search: []
        });

        var searchControl = this.formModel.find('search');
        searchControl.valueChanges
            .debounceTime(400)
            .map(str => (str.replace(' ', '-')))
            .subscribe(x => console.log(x));


        /** travel search */
        var startDates = [];
        var startDate = new Date();

        for (var day = -2; day < 2; day++) {
            var date = new Date(
                startDate.getFullYear(),
                startDate.getMonth(),
                startDate.getDate() + day
            );
            startDates.push(date);
        }

        Observable
            .fromArray(startDates)
            .map(date => {
                console.log("Getting deals for date: " + date);
                return [1, 2, 3];
            })
            .subscribe(x => console.log(x));

        /** interval */
        // Observable
        //     .interval(1000)
        //     .subscribe(x => console.log(x))

        // Observable
        //     .interval(1000)
        //     .flatMap(x => {
        //         console.log("Calling server to get latest news..");
        //         return Observable.of([1, 2, 3]);
        //     })
        //     .subscribe(news => console.log(news));

        /** delay */
        var userStream = Observable.of({
            userId: 1, userName: 'chanu'
        }).delay(2000);

        /** join */
        var tweetsStream = Observable.of([1, 2, 3]).delay(1500);

        Observable
            .forkJoin(userStream, tweetsStream)
            .map(joined => Object({user: joined[0], tweets: joined[1]}))
            .subscribe(result => console.log(result));

        /** error handling */
        var observable = Observable.throw(new Error("Something failed!"));
        observable
            .subscribe(
                x => console.log(x),
                error => console.log(error));

        /** retry */
        var counter = 0;
        var ajaxCall = Observable
            .of('url')
            .flatMap(() => {
                if (++counter < 2)
                    return Observable.throw(new Error("Request failed!"));
                return Observable.of([1, 2, 3]);
            })
            .retry(3)
            .subscribe(
                x => console.log("Response from retry: " + x),
                error => console.log(error)
            );

        /** catching and continuing */
        var remoteDataStream = Observable.throw(new Error("Something is wrong!"));
        remoteDataStream.catch(err => {
                var localDataStream = Observable.of([1, 2, 3]);
                return localDataStream;
            })
            .subscribe(x => console.log("Catching and continuing: " + x));

        /** Completed */
        Observable
            .throw(new Error("error"))
            .subscribe(
                x => console.log(x),
                error => console.log(error),
                () => console.log("Completed"));

        Observable
            .fromArray([1, 2, 3])
            .subscribe(
                x => console.log(x),
                error => console.log(error),
                () => console.log("Completed"));


    }
Example #2
0
 private handleError(error: any) {
     // console.log("Error", error);
     let errMsg = error.message || 'Server error';
     return Observable.throw(errMsg);
 }
 private handleError (error: Response) {
     console.error(error);
     return Observable.throw(error.json().error || 'Server error');
 }
 private handleError(error: Response) {
     this.notificationsService.error(this.messagesService.oops, 
                  this.messagesService.somethingWentWrong);
                  
     return Observable.throw('Server error');
 }
 spyOn(instance.imagesService, 'getProfileImages').and.callFake(() => { return Observable.throw(new Error()); });
Example #6
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.throw(error);
 });
Example #7
0
 .catch(ex => {
     this._synchronizedExcecutionInfo.next(ExecutionInfo.createFail<TResult>());
     this._exceptions.next(ex);
     return Observable.throw(ex);
 })
 private _handleError(error: Response) {
   return Rx.Observable.throw(error || 'Server error');
 }
Example #9
0
 }).catch((error: any) => {
     // console.log(error.status, "service")
     if (error.status === 409) {
         return Observable.throw(new Error(error.status));
     }
 }
 private handleError(error:any) {
   let errMsg = (error.message) ? error.message :
     error.status ? `${error.status} - ${error.statusText}` : 'Server error';
   return Observable.throw(errMsg);
 }
Example #11
0
 private handleError(error:any) {
     console.log(error);
     return Observable.throw(error.error);
 }
 .catch((err) => {
     console.log('On received an error...');
     return Observable.throw(err);
 })
Example #13
0
 private handleError (error: Response, message: string) {
   return Observable.throw(this.messageService.error(message, error.json().message || error.json().error || 'Server error'));
 }
 .flatMap(() => {
     if (++counter < 2)
         return Observable.throw(new Error("Request failed!"));
     return Observable.of([1, 2, 3]);
 })
 beforeEach(() => {
     successCb = jasmine.createSpy('successCb');
     failCb = jasmine.createSpy('failCb');
     ConstructorService.getView.and.returnValue(Observable.throw(error));
     sut.resolve(route).subscribe(successCb, failCb);
 });
		mockedHttpService.get.and.callFake((username:string) => Observable.throw(mockedErrorResponse));
Example #17
0
 handleErrors(error: Response) {
   return Observable.throw(error);
 }
Example #18
0
 .catch((err) => {
   this.logger.debug('[' + `${this.backendUrl}${url}` + '][ERROR-POST]', err);
   return Observable.throw(err);
 })
Example #19
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.throw(error, Rx.Scheduler.asap);
 });
Example #20
0
 .catch((err) => {
   this.logger.debug('[' + `${this.backendUrl}${url}` + '][ERROR-GET]', err);
   return Observable.throw(err.json().error || 'Server error');
 });
Example #21
0
 .catch((error: any) => Observable.throw(error));
Example #22
0
.catch((error:any) => Observable.throw(console.log("This is an error")))
 spyOn(instance.userService, 'addUser').and.callFake(() => { return Observable.throw(new Error()); });
Example #24
0
 _handlerError(err: any) {
   console.log(err); // log this somewhere and format the message well for devs
   return Observable.throw(err); // our opportunity customize this error
 }
 private static handleError(error: Response | any) {
     console.error('An error occurred', error);
     return Observable.throw(error.message || error);
 }
 private handleError(error: any) {
     console.error(error);
     return Observable.throw(error || 'Server error');
 }
Example #27
0
 _handlerError(err : any){
     console.log(err);
     return Observable.throw(err);
 }
 beforeEach(() => {
     authService.login.and.returnValue(Observable.throw('error'));
     sut.login();
 });
	static handleErrors(error: Response) {
		console.log(JSON.stringify(error.json()));
		return Observable.throw(error);
	};
Example #30
0
 .catch((error: any) => Observable.throw(error.json().error || 'Server error')); //...errors if