1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular HttpClient interceptor: Error 429 returns status 0 instead of 429

Discussão em 'Angular' iniciado por Nicker Pasco, Junho 8, 2025.

  1. Nicker Pasco

    Nicker Pasco Guest

    I am working with an Angular HTTP interceptor and handling various error status codes. However, I have an issue with handling the 429 (Too Many Requests) error code. While the backend correctly responds with a 429 status in tools like Postman, in Angular, I receive errorResponse.status = 0 instead of 429 when the request returns this error.

    When the backend responds with status codes 200, 500, or 401, my interceptor handles the errors correctly. But when the server responds with 429, errorResponse.status is set to 0.

    I tested the same request in Postman, and the server correctly returns a 429, but this is not happening in Angular.

    Here is a snippet of the interceptor code:

    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    let accessToken = sessionStorage.getItem("access_token");
    if (request.url !== './assets/config/env.json') {
    request = request.clone({
    setHeaders: {
    Authorization: `Bearer ${accessToken}`,
    sid: `${this.config.getEnv('sid')}`,
    }
    });
    }
    return next.handle(request).pipe(
    tap(
    event => this.handleResponse(request, event),
    error => this.handleError(request, error)
    )
    );
    }
    handleError(req: HttpRequest<any>, errorResponse: HttpErrorResponse) {
    if (errorResponse.status === 429) {
    this.mostrarMensajeNoDuplicado("You have reached the user request limit, try again later.");
    }
    }

    Continue reading...

Compartilhe esta Página