nacho_dh's answer was close, but res is an object that is unlikely to be null. In the case where I had this problem, the res object was a valid object, but the _body property was', this is what causes res.json () to throw an exception. Therefore you need to:
.map(res => (<any>res)._body == '' ? {} : res.json())
Please note that when working with Angular 2 and therefore Typescript you need to send res to <any> because _body is private and Typescript will not allow you to access it.
yes i know its hacked, thanks
source share