Currently I'm migrating from http to HttpClient (@angular/common/http). Everything is working except the delete statement. I assume angular tries to parse the result as I get an error: "Unexpected end of JSON input ...". I'm not interested in the result detail, only if deletion was successfull or not.
So my code is:
Service:
public cancelReservation(reservationId: String) {
if (!reservationId) {
return null;
}
return this.httpClient.delete(environment.baseUrl + '/api/reservations/' + reservationId);
}
Calling code:
this.reservationService.cancelReservation(this.reservation.id).subscribe (result => {
this.handleSuccess();
}, error => {
this.handleError();
});
I simplified the success and error handling. The post and get request is build the same way - but only delete is failing.
I tried an alternative, but with the same result:
this.reservationService.cancelReservation(this.reservation.id).toPromise().then(() => {
this.handleSuccess();
}).catch(() => {
this.handleError();
});