I notice that I can raise or return, producing 500 or 200 responses. for example:
def random(request):
coin = [true, false]
if random.choice(coin):
succeed()
else:
fail()
def succeed():
return '{ "status": "success!"}'
def fail():
raise Exception("failure")
something roughly like that will produce either a 500 or a 200 response. But it doesn't, for example, let me raise a 422 error with a body.
Can I do that?
Google Cloud Functions is a stateless execution environment, which means that the functions follow a shared-nothing architecture. Each running function is responsible for one and only one request at a time.
Functions are stateless, and the execution environment is often initialized from scratch, which is called a cold start. Cold starts can take significant amounts of time to complete.
Function execution time is limited by the timeout duration, which you can specify when you deploy a function. By default, a function times out after one minute (60 seconds), but you can extend this period: In Cloud Functions (1st gen), the maximum timeout duration is nine minutes (540 seconds).
Under the hood, Cloud Functions is just using Flask, so you can return anything that you can return from a Flask endpoint.
You can just return a body and a status code together like this:
def random(request):
...
return "Can't process this entity", 422
Or, you can return a full-fledged Flask Response
object:
import flask
def random(request):
...
return flask.Response(status=422)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With