0

I have question related to angular http requests. I'll send POST request with some data, if server return 404 status I need to modify data (in response body will be invalid data - I will remove them). I will repeat this action until I get response status 200. And now question :) How can I achieve it with angular 2 syntax?

1 Answer 1

0

That will actually be a recursive call that you will make with modified data each time you get response code other than 200. Please see the following code snippet:

  myFunction(someData): void {

    this.myService.serviceFunction(someData).subscribe(
      response => {

        if (response.status !== 200) {
          //modify your data
          myFunction(modifiedData);
        }
      },
      err => {
          //deal error response
          if (err.status !== 200) {
          //modify your data
          myFunction(modifiedData); 
          }
      }
    );
  }
Sign up to request clarification or add additional context in comments.

Comments

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.