Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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));
}),
);
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))
}
}
}
// 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;
}
}
}
}
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}`);
}
}
}
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', () => {
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', () => {
catchError(err =>
throwError(new HttpException('New message', HttpStatus.BAD_GATEWAY)),
),
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);
}
errorHandler(error: HttpErrorResponse){
return observableThrowError(error.message || "Server Error");
}
catchError(err => {
this.toasterService.error(
snq(() => err.error.error_description, 'AbpUi::DefaultErrorMessage'),
'AbpUi::Error',
);
return throwError(err);
}),
)