How can I not retry on error 400 and just console.log the error?

Discussão em 'Angular' iniciado por Christos Segkani, Novembro 25, 2024.

  1. @Injectable()
    export class RetryInterceptor implements HttpInterceptor {
    private keycloakService = inject(KeycloakService);

    intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
    // console.log(this.keycloakService.getKeycloakInstance()?.tokenParsed);
    // console.log(request);

    return next.handle(request).pipe(
    retry({
    count: 3,
    delay: (error, retryCount) => {
    if (error.status === 503 || error.status === 504) {
    return timer(1000); // retry every 1 second for 503 and 504
    }
    return timer(retryCount * 1000); // Retry with increasing delay
    }
    }),
    catchError((error) => {
    if (error.status === 401) {
    return this.handleUnauthorized(request, next);
    }
    if (error.status === 503 || error.status === 504) {
    // message that will redirect to the local UI URL if it comes back 503/504.
    }

    if (!noDisplayError) {

    }
    throw error;
    })
    );
    }

    Continue reading...

Compartilhe esta Página