2

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.

6
  • could you subscribe to the request directly (i.e. remove the .map) and see if that gives you some more information - it could be that it is failing to parse the response for some reason Commented Jul 22, 2017 at 13:15
  • @0mpurdy Just tried, still getting the same error without the .map Commented Jul 22, 2017 at 13:24
  • can you do console.log(err) and get any more information? Commented Jul 22, 2017 at 13:25
  • @0mpurdy Simply an error object with code 0 and message null. Commented Jul 22, 2017 at 13:36
  • Ok I think it is answered by this answer it's for angularjs but it is probably still a CORS error, hopefully that's enough for you to sort your problem! An angular 2 related question would be this one Commented Jul 22, 2017 at 13:42

1 Answer 1

1

This looks like a CORS error described similarly here for angularjs and with more explanation in this answer for Angular 2

The solution is adding a header server side to handle CORS.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.