How to use the rxjs.throwError 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 Azure / BatchExplorer / app / services / azure-http.service.ts View on Github external
mergeMap((error, i) => {
                const retryAttempt = i + 1;
                // if maximum number of retries have been met
                // or response is a status code we don't wish to retry, throw error
                if (
                    retryAttempt > Constants.badHttpCodeMaxRetryCount ||
                    !RetryableHttpCode.has(error.status)
                ) {
                    return throwError(error);
                }
                // retry after 1s, 2s, etc...
                return timer(100 * Math.pow(3, retryAttempt));
            }),
        );
github intershop / intershop-pwa / src / app / core / interceptors / auth.interceptor.ts View on Github external
catchError(err => {
        if (AuthInterceptor.isAuthTokenError(err)) {
          this.store.dispatch(new ResetAPIToken());

          // retry request without auth token
          const retryRequest = req.clone({ headers: req.headers.delete(ApiService.TOKEN_HEADER_KEY) });
          // timer introduced for testability
          return timer(10).pipe(switchMapTo(next.handle(retryRequest)));
        }
        return throwError(err);
      }),
      tap(event => this.setTokenFromResponse(event))
github forCrowd / WealthFramework / AngularClient / src / main / core / app-http.service.ts View on Github external
}
            }
        }

        // No error message? Set a generic one
        if (errorMessage === "") {
            errorMessage = "Something went wrong with your request. Please try again later!";
        }

        // Display the error message
        this.logger.logError(errorMessage);

        if (handled) {

            // If handled, continue with Observable flow
            return observableThrowError(error);

        } else {

            // Else, let the internal error handler handle it
            if (error instanceof Response) {
                const message = `status: ${error.status} - statusText: ${error.statusText} - url: ${error.url}`;
                throw new Error(message);
            } else {
                throw error;
            }
        }
    }
}
github flowup / api-client-generator / tests / github / api / services / markdown / markdown-api-client.service.ts View on Github external
return this.http.delete(`${this.domain}${path}`, options);
      case 'GET':
        return this.http.get(`${this.domain}${path}`, options);
      case 'HEAD':
        return this.http.head(`${this.domain}${path}`, options);
      case 'OPTIONS':
        return this.http.options(`${this.domain}${path}`, options);
      case 'PATCH':
        return this.http.patch(`${this.domain}${path}`, body, options);
      case 'POST':
        return this.http.post(`${this.domain}${path}`, body, options);
      case 'PUT':
        return this.http.put(`${this.domain}${path}`, body, options);
      default:
        console.error(`Unsupported request: ${method}`);
        return throwError(`Unsupported request: ${method}`);
    }
  }
}
github Sunbird-Ed / SunbirdEd-portal / src / app / client / src / app / modules / resource / modules / player / components / content-player / content-player.component.spec.ts View on Github external
xit('should throw error if content api throws error', () => {
    const userService = TestBed.get(UserService);
    const playerService = TestBed.get(PlayerService);
    const resourceService = TestBed.get(ResourceService);
    resourceService.messages = resourceServiceMockData.messages;
    resourceService.frmelmnts = resourceServiceMockData.frmelmnts;
    const windowScrollService = TestBed.get(WindowScrollService);
    spyOn(windowScrollService, 'smoothScroll');
    spyOn(playerService, 'getContent').and.returnValue(observableThrowError(serverRes));
    userService._userData$.next({ err: null, userProfile: mockUserData });
    fixture.detectChanges();
    expect(component.playerConfig).toBeUndefined();
    expect(component.showError).toBeTruthy();
    expect(component.errorMessage).toBe(resourceService.messages.stmsg.m0009);
  });
  it('should open the pdfUrl in a new tab', () => {
github Sunbird-Ed / SunbirdEd-portal / src / app / client / src / app / modules / learn / components / course-consumption / course-consumption-page / course-consumption-page.component.spec.ts View on Github external
it('should navigate to course view page if fetching enrolled course fails', () => {
    spyOn(learnerService, 'get').and.returnValue(throwError(enrolledCourse.courseSuccessEnroll));
    courseService.initialize();
    component.ngOnInit();
    expect(component.toasterService.error).toHaveBeenCalled();
    expect(component.navigationHelperService.navigateToResource).toHaveBeenCalledWith('/learn');
  });
  it('should fetch course details if it not enrolled course and should not fetch enrolled batch details', () => {
github nestjs / nest / sample / 01-cats-app / src / common / interceptors / exception.interceptor.ts View on Github external
catchError(err =>
          throwError(new HttpException('New message', HttpStatus.BAD_GATEWAY)),
        ),
github lordfriend / Deneb / src / helpers / base.service.ts View on Github external
error = new AuthError(resp.json().message, resp.status);
            } else {
                error = new ClientError(resp.json().message, resp.status);
            }
        } else if (resp.status === 401) {
            error = new AuthError(resp.json().message, resp.status);
        } else if (resp.status == 403) {
            error = new AuthError(resp.json().message, resp.status);
        } else if (resp.status === 500) {
            error = new ServerError(resp.json().message, resp.status);
        } else if (resp.status === 502) {
            error = new ServerError('Server offline', resp.status);
        } else {
            error = new ServerError('Network Error', 0);
        }
        return observableThrowError(error);
    }
github gopinav / Angular-Tutorials / v6-services-and-http / src / app / employee.service.ts View on Github external
errorHandler(error: HttpErrorResponse){
    return observableThrowError(error.message || "Server Error");
  }
github abpframework / abp / npm / ng-packs / packages / account / src / lib / components / tenant-box / tenant-box.component.ts View on Github external
catchError(err => {
            this.toasterService.error(
              snq(() => err.error.error_description, 'AbpUi::DefaultErrorMessage'),
              'AbpUi::Error',
            );
            return throwError(err);
          }),
        )