Angular get string instead HTTPReponse object

57 Views Asked by At

I have an issue because err is returning a string instead of a HttpResponse. I am not sure why, the server returns the content type as "application/json".

Version of Angular is 13.

return this.http.delete(
  "http://Localhost:8080/delete",
  { headers: { 'Content-Type': 'application/json' } }
).pipe(
  catchError((err, caught) => {
    return of(false); 
  }),
  map(() => {
    return true;
  })
)

I am not sure why doesn’t work

1

There are 1 best solutions below

2
Meqwz On

You use RxJS first to catch any errors, throw away the actual error response, and return the boolean false. Then, if the request is successful, you are using RxJS to map that successful response, throw away the actual response, and return the boolean true. If you want an HTTP response, don't use the RxJS you've added in the pipe() operator. Handle errors and any other logic in your subscription instead.