net::ERR_CONNECTION_REFUSED : I’d like to access an API server, but the server hasn’t started. Then I got the error :

http://localhost:3000/api/heroes net::ERR_CONNECTION_REFUSED

Could I handle this according to the status of the response ?

Solution 1 :

//First inject the router in the constructor

private handleError (error: Response | any) {
//Your other codes    

if (error.status == 0){ //or whatever condition you like to put

Solution 2 :

If you are using spring for the backend , just add the annotation @crossorigin in your rest controller to allow your front consuming the API

@CrossOrigin // you can add (origins = "http://localhost:4200") to set only one source


  1. Pingback: Solution for : Access to XMLHttpRequest from origin has been blocked by CORS policy

Laisser un commentaire