0

I have following in angular 7.

public deleteId(pId){
    return this.http.delete<any>(this.deleteUrl(pId), {observe: 'response'})
      .pipe(catchError(this.handleError));
  }

Delete method (I want 202 code here in response.status)

public deleteMethod(): void {
    this.service.deleteId(this.id)
      .subscribe(response => {

       console.log(`Delete response ` , response);

        if(response.status === 200) {
          console.log('Deleted successfully');
        }
       else if(response.status === 202) {
          console.log('something else'); // I am not getting response.status here
        }
    });
  }

I am getting status code 200 properly but, 202 i am getting in handleError method. I want 202 as a response. How can i get that?

private handleError(error: HttpErrorResponse) {
  //It sends me to this function.
}
4
  • Can you include what the error variable contains in the handleResponse method in the event of a 202 status? Commented Sep 17, 2019 at 14:47
  • @Igor What do you mean? I think this you are asking forresponse.status Commented Sep 17, 2019 at 14:53
  • @ketan it's really unclear what you are asking. Can you elaborate more? Commented Sep 17, 2019 at 15:05
  • @PaoloCasciello I edited. When i run application API called and if response status is 202 it send me to handleError function instead of .subscribe(response Commented Sep 17, 2019 at 15:14

2 Answers 2

0

Finally i got solution with following:

public deleteId(pId){
    return this.http.delete<any>(this.deleteUrl(pId), {observe: 'response', responseType: 'text' as 'json'})
      .pipe(catchError(this.handleError));
 }

Added , responseType: 'text' as 'json'

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

Comments

-1
public deleteMethod(): void {
this.service.deleteId(this.id)
  .subscribe(response => {

   console.log(`Delete response ` , response);

    if(response.status === 200) {
      console.log('Deleted successfully');
    }
  },
  err => {
    console.log(err.status); // ----> Here's your error
    if(err.status === 202) {
      // do your stuff
    }
  }
);

}

2 Comments

No. I want 202 in response, as it's success status code
stackoverflow.com/questions/43683052/… that should be the answer u are searching for

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.