Google App Engine Request Status
Is it possible to set the http request status to 200 even if the system throws 500? I have a task which is running. When GA开发者_JAVA百科E throws http request 500 i want to manually set it to 200 at end of task so as to prevent the task from being retried.
The typical pattern to return a 200 status code is to wrap your code between try
and except
clauses:
try:
do your stuff
except:
logging.error("Something bad happened")
This example catch all the exceptions returning always a 200 status code
, in your application you might want to add a proper list of exceptions to catch; for certain types of transient exceptions it is correct to raise a 500 error that implicitly say to App Engine to try the task again.
EDIT:
As correctly suggested, you should use logging.exception
instead of logging.error
to include the stacktrace in the log.
try:
do your stuff
except:
logging.exception("Something bad happened") #It will log the stacktrace too
This has a second benefit, it allows you to receive log reports via email after enabling the ereporter service.
精彩评论