HttpError 0 when accessing Google Cloud Function

I am getting an HttpError 0 when trying to access a google cloud function from client side of Anvil.

Strangely, when I use the Talend API checker (a REST tool) from the same browser it works fine. I can’t even use OPTIONS without getting the HttpError. Do I need to set a header at all.

You will find it in the code attached to the TRY BROWSER HTTP in the attached app.

https://anvil.works/build#clone:5MXAHPQ7HQVBM54F=3FRJQBXB7K7AAUVEN25VMA3O

My ultimate goal is to get access to a localhost server on the client. I am just using cloud functions as a test because I am on my Chromebook at the moment.

I haven’t checked your app yet, but this is often an issue with CORS (cross origin requests).

Try the request using something like https://resttesttest.com/
and see if the result is the same.

If you check the console in your browser dev tools, that might also show you the error in more detail (I suspect highlighting a CORS issue).

Hi there,

As @david.wylie says, this is usually a symptom of a CORS issue. You’ll need to either update the CORS headers returned by your Google cloud function, or make the request from the server (which isn’t bound by CORS rules) rather than the browser (which is).

Here’s the relevant section of the anvil.http documentation:
https://anvil.works/docs/http-apis/making-http-requests#browser-restrictions

1 Like