rxjs#TimeoutError TypeScript Examples

The following examples show how to use rxjs#TimeoutError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: error.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
toastError$<T = unknown>(error: T) {
    return this.translocoService
      .selectTranslateObject<{ [key: string]: string }>('error')
      .pipe(
        first(),
        map(
          ({
            validationError,
            authenticationError,
            notFoundError,
            serverInternalError,
            internetError,
            timeoutError,
            unknownError,
          }) => {
            // eslint-disable-next-line no-debugger
            if (typeof error === 'string') return error;
            if (error instanceof HttpErrorResponse) {
              if (error.status === HttpErrorCode.INVALID)
                return validationError;
              if (error.status === HttpErrorCode.AUTHENTICATION)
                return authenticationError;
              if (error.status === HttpErrorCode.NOT_FOUND)
                return notFoundError;
              if (error.status >= HttpErrorCode.INTERNAL)
                return serverInternalError;
              return internetError;
            }
            if (error instanceof TimeoutError) return timeoutError;
            if (error instanceof Error) return error.message;
            return unknownError;
          }
        ),
        concatMap(
          message =>
            new Promise<T>(resolve =>
              this.toastController
                .create({ message, duration: 2000, color: 'danger' })
                .then(toast => toast.present())
                .then(() => {
                  console.error(error);
                  resolve(error);
                })
            )
        ),
        concatMapTo(EMPTY)
      );
  }