Q:

Angular2 http.get throws EXCEPTION: Error: Uncaught (in promise): Cannot read property 'toString' of null

Today I have come across an error thrown by get method of Http module of Angular2 and it took me a while to figure out the solution so I decided to put it here and make someones life less painful. Otherwise, if you like to spend hours debugging angular/core then don't read it :).
My use case is about sending GET request without body payload with jwt token set to header like this:
let headers = new Headers();

headers.append('Content-Type', 'application/json');
headers.append('Authorization', token);

let options = new RequestOptions({
    headers: headers
});

And then I was making a get request to localhost where I have server running:
return this.http.get('http://localhost:3000/someApiUrl', options)
    .toPromise()
    .then(this.extractData)
    .catch(this.handleError);

But whatever I do Angular is throwing an exception
EXCEPTION: Error: Uncaught (in promise): Cannot read property 'toString' of null

A:

Angular was throwing exception because GET request was sent without a body and there is no check for null. So, when Angular was trying to coerce body of the request to string it was actually calling toString() method on null.
The solution is to set the body explicitly to empty string like so:
    let options = new RequestOptions({
        headers: headers,
        body: ''
    });

