I am trying to get the response body of a HttpClient Post request. This is kinda where I am at right now, although I have tried a dozen different variations of this based of of the hundreds of frustratingly useless examples online.
return this._http
.post<HttpResponse<any>>(
apiURL,
request,
{
headers: new HttpHeaders({
'Content-Type': 'application/json'
}),
observe: 'response' as 'body'
}
)
.pipe(
map((response: HttpResponse<any>) => {
if (response.status === 200 || response.status === 406) {
return response.body as RequestResponse;
}
throw Error("There was an error processing your request.");
})
);
The API, which I have no control over returns a 406 with a response body that I need to access. However I cannot for the life of me get this to enter the map there. I can catchError in the pipe and stop at a breakpoint there, but the "error" in that response is just [].
catchError((error: HttpErrorResponse) => {
return throwError(error); <-- error is always [];
})
Mind you, I don't necessarily want to throwError there, I have tried other things but if error is always [], its pretty useless anyway.
The api itself is a C# azure function, and returns:
ObjectResult(theObjectINeed) { StatusCode = StatusCodes.Status406NotAcceptable }
I would basically like to just swallow the 406 and return the response body to the subscriber. I have been searching for hours on how to do this, but the docs are horrible, and most of the search results return stuff that is years old, which probably worked at one point, but no longer.