I'm using ionic with a google cloud function and when I return data to my application angular defaults to handling it as an error.
Here's my cloud function call back using node: I have already tried adding curly braces to payload and but it didn't help.
function (error, response, body) { let payload = parser.toJson(body, parserOptions); console.log(payload) res.status(200).send(payload); } In the console logs for that call back I get:
{ ResponseCode: '0', referenceID: '22072017152436718488608295', ResponseMessage: 'SUCCESS', paymentURL: 'url', net_amount: '0', invoiceNumber: '0', status: '200' } Which is the data I expect to receive in my Angular/Ionic code. Testing this in Postman works too.
Angular Code:
return this.http.post('/api', body, headers) .map(res => res.json()) .subscribe( data => { console.log('Success') console.log(data) }, err => { console.log('Error') console.log(err.status) console.log(err.message) } ) I get an error status of 0 and error message of null.
.map) and see if that gives you some more information - it could be that it is failing to parse the response for some reasonconsole.log(err)and get any more information?