1

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();
        });

1 Answer 1

4

I had the same problem. Try to add { observe: 'response', responseType: 'text' } to your request. this.http.post(this.createTagUrl, tagDetails, { observe: 'response', responseType: 'text' });

Or change the version of HttpModule to 4.3.5. In this version it works.

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

Comments

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.