[Solved] Custom Errorhandler doesn’t work on Google Cloud Run [closed]


I have made a replica of your case but in my case the custom error handler works. I created this example since cloud shell editor. I share with you my code I hope are helpful for you:

app.py:

"""
A sample Hello World server.
"""
import os
import requests
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from flask import Flask, render_template

# pylint: disable=C0103
app = Flask(__name__)
limiter = Limiter(
    app,
    key_func=get_remote_address,
    default_limits=["2 per minute", "1 per second"],
)


@app.route("https://stackoverflow.com/")
def hello():
    """Return a friendly HTTP greeting."""
    message = "It's running!"

    """Get Cloud Run environment variables."""
    service = os.environ.get('K_SERVICE', 'Unknown service')
    revision = os.environ.get('K_REVISION', 'Unknown revision')

    return render_template('index.html',
        message=message,
        Service=service,
        Revision=revision)
    

@app.errorhandler(429)
def page_not_foundes(e):
    # note that we set the 429 status explicitly
    return render_template('429.html')

if __name__ == '__main__':
    server_port = os.environ.get('PORT', '8080')
    app.run(debug=False, port=server_port, host="0.0.0.0")

requeriments.txt:

Flask==1.1.2
requests==2.25.1
ptvsd==4.3.2 # Required for debugging.
Flask-Limiter==1.4

Custom html was created on directory templates
429.html

<h1>MY CUSTOM 429</h1>

After I send two request I successfully watch my custom error. I hope my code helps you 😀

solved Custom Errorhandler doesn’t work on Google Cloud Run [closed]