0

I am making a web service call in Angular 5, using the HttpClientModule, and it works for all 200 statuses response. But, if there is any 400 statuses it just waits and waits and waits and eventually get a 503 status.

For example, if I call this function with correct username/password, it works, I get 200 status back, and the User object. But, if I pass in incorrect username/password, I dont get the 400 error, I get a 503 error after about a minute.

The server side log shows that the webservice is returning a 400 status to my request, but nothing comes back.

Here is my web service call code:

login(username: string, password: string): Observable<boolean> {
  const url = this.getUrl('/v1/users/login');
  const headers = {
    headers: new HttpHeaders({'Content-Type': 'application/json', 'transactionId': uuid.v4()})
  };
  const body = { username, password };

  return new Observable<boolean>( observer => {
    this.http.post<User>(url, body, headers).subscribe(
      (user: User) => {
        console.log('login: Success: ', user);
        observer.next(true);
      },
      (err: HttpErrorResponse) => {
        console.log('login: Error: ', err);
        observer.next(false);
      }
    );
  });
}

Here is the Chrome Network log:

12
  • What do you see in the network panel? Ultimately angular hands off a request to the browser and then it's between the browser and the server until the response comes back. Commented Dec 15, 2017 at 5:26
  • Posted image of the Chrome Network log Commented Dec 15, 2017 at 5:48
  • Is my code correct to handle error responses? Commented Dec 15, 2017 at 5:49
  • I'm still a noob with anything beyond angular 1.x myself but it looks reasonable off hand, other thing is based on your image of the network request it's something after your web server has said 400 bad credentials or whatever and the response being sent to the browser (since it sees a 503) you can right click the request in the network panel and copy as curl request then paste that in a unix terminal with curl installed (or cygwin) and see the request outside of the browser but will likely get the same 503 response. Basically I'm thinking something on heroku config maybe? Commented Dec 15, 2017 at 5:52
  • Here is a wrinkle. It works in postman and returns the 400 error no problem. Commented Dec 15, 2017 at 5:54

1 Answer 1

1

Turns out the server had a bug in it. It was getting an error in the log regarding "media type". Once that was resolved, the server is now sending back correct error responses and my code is handing them.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad you figured it out and was in fact something server side. In most cases angular isn't really to blame or suspect in situations like this because the httpservice is basically a wrapper around the xhr object native to browsers (also widely used and tested)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.