How to use the rxjs/operators.catchError function in rxjs

To help you get started, we’ve selected a few rxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fabric8-ui / fabric8-ui / src / app / services / area.service.ts View on Github external
getAreas(): Observable {
    // get the current iteration url from the space service
    if (this._currentSpace) {
      let areasUrl = this._currentSpace.relationships.areas.links.related;
      if (this.checkValidUrl(areasUrl)) {
        return this.http
          .get<{data: AreaModel[]}>(areasUrl)
          .pipe(
            map(response => {
              return response.data as AreaModel[];
            }),
            map((data) => {
              this.areas = data;
              return this.areas;
            }),
            catchError((error: Error | any) => {
              if (error.status === 401) {
                //this.auth.logout(true);
              } else {
                console.log('Fetch area API returned some error - ', error.message);
                return Promise.reject([] as AreaModel[]);
              }
            })
          );
      } else {
        this.logger.log('URL not matched');
        return ObservableOf([] as AreaModel[]);
      }
    } else {
      return throwError('nospace');
    }
  }
github DeborahK / MovieHunter-communication / MH-5 / src / app / movies / movie.service.ts View on Github external
if (id === 0) {
          // Clear any selection
          this.currentMovie = null;
          return of(this.initializeMovie());
        }
        if (this.movies) {
            const foundItem = this.movies.find(item => item.id === id);
            if (foundItem) {
                return of(foundItem);
            }
        }
        const url = `${this.moviesUrl}/${id}`;
        return this.http.get(url)
                        .pipe(
                            tap(data => console.log('Data: ' + JSON.stringify(data))),
                            catchError(this.handleError)
                        );
    }
github trustwallet / platform / src / app / auth / services / providers / wallet-connect / wallet-connect.service.ts View on Github external
// Close QR Code Modal
            WalletConnectQRCodeModal.close();

            result.next(true);
          });
          return result;
        }),
        switchMap(() => fromPromise(this.connector.getAccounts()))
      ) as unknown) as Observable;
    } else {
      result = ((fromPromise(
        this.connector.getAccounts()
      ) as unknown) as Observable).pipe(
        timeout(1000),
        catchError(error => this.connect(true))
      );
    }

    this.connector.on("disconnect", (error, payload) => {});

    return result;
  }
github GNS3 / gns3-web-ui / src / app / services / http-server.service.ts View on Github external
options(server: Server, url: string, options?: JsonOptions): Observable {
    options = this.getJsonOptions(options);
    const intercepted = this.getOptionsForServer(server, url, options);
    return this.http
      .options(intercepted.url, intercepted.options)
      .pipe(catchError(this.errorHandler.handleError)) as Observable;
  }
github spring-cloud / spring-cloud-dataflow-ui / ui / src / app / shared / services / shared-about.service.ts View on Github external
loadAboutInfo(reload?: boolean): Observable {
    if (!this.aboutInfo || reload) {
      this.httpClient
        .get(this.aboutUrl)
        .pipe(
          map(this.extractData.bind(this)),
          catchError(this.errorHandler.handleError)
        ).subscribe();
    }
    return of(this.aboutInfo);
  }
github edbzn / reactive-blog / packages / client / src / app / components / admin / store / editor.epics.ts View on Github external
switchMap(({ payload }) =>
      loadConverterModule$.pipe(
        map(converterModule => {
          const converter = new converterModule.default.Converter();
          return convertMdToHtml(converter.makeHtml(payload));
        }),
        catchError(err => of(failure(err)))
      )
    )
github maartenl / Land-of-Karchan / karchanpersonal / src / main / karchanpersonal / src / app / player.service.ts View on Github external
public getWikipagePreview(contents: string): Observable {
    if (!environment.production) {
      return new Observable(observer => {
        observer.next('<p>This is a <i>preview</i></p>');
        observer.complete();
      });
    }
    const headers = new HttpHeaders()
      .append('Content-Type', 'text/html; charset=utf-8')
      .append('Accept', 'text/html');
    return this.http.post(this.wikipagesPreviewUrl, contents, { responseType: 'text' , headers })
      .pipe(
        catchError(err =&gt; {
          this.handleError(err);
          return [];
        })
      );
  }
github dbelob / guess-game / guess-game-web / src / app / shared / services / state.service.ts View on Github external
getNamePictures(): Observable {
    return this.http.get(`${this.baseUrl}/name-pictures`)
      .pipe(
        catchError((response: Response) =&gt; {
          this.messageService.reportMessage(response);
          throw response;
        })
      );
  }
}
github openaccounting / oa-web / src / app / core / api.service.ts View on Github external
getAccounts (date?: Date): Observable {
    this.log.debug('API getAccounts()');
    let url = this.url + '/orgs/' + this.orgId + '/accounts';
    if(date) {
      url += '?date=' + date.getTime();
    }
    return this.http.get(url, this.httpOptions)
      .pipe(catchError(this.handleError));
  }
github johnpapa / angular-ngrx-data / lib / src / dataservices / default-data.service.ts View on Github external
case 'PUT': {
        result$ = this.http.put(url, data, options);
        if (this.saveDelay) {
          result$ = result$.pipe(delay(this.saveDelay));
        }
        break;
      }
      default: {
        const error = new Error('Unimplemented HTTP method, ' + method);
        result$ = throwError(error);
      }
    }
    if (this.timeout) {
      result$ = result$.pipe(timeout(this.timeout + this.saveDelay));
    }
    return result$.pipe(catchError(this.handleError(req)));
  }