2

I want to show popup with url when for example firewall is blocking any of them from my backend. I should get 403 status response, but all the time Im getting status 0.

I see similar topic here but I dont know whether should I use it:

Angular http returning status 0, but I expect 404

is that a good point with that solution? If yes then how or where should I use it?

In my service there should be only error.status == 403 but I cannot figure out how to get real status and not 0.

I dont think that CORS is the problem because if firewall block my request then It will never hit the backend. Am I right?

this.httpClient.request(request).toPromise()
                .then(
                    (res: any) => { // Success
                        resolve(res.body);
                    },
                    (error: any) => { // Error
                        if (error.status == 403){
                            this.respondedWithError$.emit(error.url);
                        }
                        if (error.status == 0){
                            this.respondedWithError$.emit(error.error.currentTarget.__zone_symbol__xhrURL);
                        }
                        reject(error.error);
                    }
                );

Current result:

message: "Http failure response for (unknown url): 0 Unknown Error"
name: "HttpErrorResponse"
status: 0
statusText: "Unknown Error"

Expected result:

status: 403
plskrdar
  • 51
  • 6

1 Answers1

0

This is not an issue with Angular, you need to investigate at the server-side.

If you look at the network tab, you'll see that your request is never actually sent and that's why you do not get the server-response you expect.

This is a CORS issue and you need to make sure that the OPTIONS preflight request is implemented in the right way, e.g. responds with a success code and sends the right headers for your request.

Valentin Klinghammer
  • 1,319
  • 1
  • 13
  • 19