While trying to do a HTTP Post request I am receiving the following error:
auth.service.ts?c694:156 Something went wrong requesting a new password, erro
I had a very similar issue. It also ended up being a problem with an HTTP interceptor. I had an automatic deserialization function running on all responses with a particular API endpoint pattern. Responses which weren't instances of HTTPResponse
ended up being eaten. Adding an else statement which returned the response untouched when not an instance of HTTPResponse
solve the issue for me:
@Injectable()
export class DeserializerInterceptor implements HttpInterceptor {
public intercept(request: HttpRequest, next: HttpHandler): Observable> {
return next.handle(request).map(
event => {
if (event instanceof HttpResponse) {
let response = event as HttpResponse;
// ... deserialization of response object
return response;
} else {
return event; // ... adding this else statement fixed the `undefined` error.
}
}
);
}
}
(Removed error handling code, for clarity.)