I'm testing some google cloud functions locally by making a small test application in angular and a Cloud-Function. I am trying to read the response back from the Cloud-Function when I make a post request. The cloud function then returns an error with the data inside of it instead of just the actual data. Curiously if I don't subscribe to the server's response, then I never see an error in the console, meaning it must be a setting on the cloud function itself. However, I copied and pasted the cloud function code straight from the documentation. Please help.
TL;DR: Http Cloud-Function returning an error instead of data, why?
Here is the code for the cloud function:
exports.helloWorld = functions.https.onRequest((request, response) => { response.header('Access-Control-Allow-Origin', '*'); response.status(200).send('poop'); }); Here is the code for the test post:
test() { var req = this.http .post( 'http://localhost:5000/merchantapi-b7b17/us-central1/helloWorld', JSON.stringify({ poop: 'poop' }) ) .subscribe(_val => { console.log(_val); }); } Here is the error I get on the console:
HttpErrorResponse error: {error: SyntaxError: JSON Parse error: Unexpected identifier "poop", text: "poop"} headers: HttpHeaders {normalizedNames: Map, lazyUpdate: null, lazyInit: function} message: "Http failure during parsing for http://localhost:5000/merchantapi-b7b17/us-central1/helloWorld" name: "HttpErrorResponse" ok: false status: 200 statusText: "OK" url: "http://localhost:5000/merchantapi-b7b17/us-central1/helloWorld" HttpErrorResponse Prototype defaultErrorLogger — core.js:6014 handleError — core.js:6066 next — core.js:40558 (anonymous function) — core.js:35336 __tryOrUnsub — Subscriber.js:185 next — Subscriber.js:124 _next — Subscriber.js:72 next — Subscriber.js:49 next — Subject.js:39 emit — core.js:35298 run — zone-evergreen.js:124 onHandleError — core.js:39735 runTask — zone-evergreen.js:171 invokeTask — zone-evergreen.js:465 timer — zone-evergreen.js:2650 defaultErrorLogger — core.js:6014 As you can see the error contains the data, and I can use that, but I'd like to understand why its sending an error and how to squash it.