mani
mani

Reputation: 55

Return custom error from appengine behind Google Cloud Endpoints

I am using flask and python 3.6 as a backend service that is deployed to App Engine in GCP. This backend is sitting behind Google Cloud Endpoints deployed in Cloud Run. Endpoints takes all my 404 messages and just returns 404 Not Found. I want to send a more informative error message with the 404 code. Is there any way to do so using my current setup? Thanks

Upvotes: 0

Views: 86

Answers (2)

Jose V
Jose V

Reputation: 1496

You can use the Python Endpoints library to send HTTP error codes with a custom message as follows:

message = 'No entity with the id "%s" exists.' % entity_id
raise endpoints.NotFoundException(message)

You can find more info in the docs

Upvotes: 0

ASSILI Taher
ASSILI Taher

Reputation: 1349

You can create a custom 404 html page:

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

Then, you need to create 404.html file.

Upvotes: 1

Related Questions