Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

367
Vistas
Flask Middleware Class Raise Exception Not Catching

Here is part of app.py:

app = Flask(__name__)
app.config.from_object('SETTINGS')
app.wsgi_app = Middleware(app.wsgi_app, app)


@app.errorhandler(ValueError)
def all_exception_handler(error):
    print('Error Catched!')
    return 'Error Handler', 500

And here is part of Middleware class:

class Middleware:
    def __init__(self, wsgi, app):
        self.wsgi = wsgi
        self.app = app


    def __call__(self, environ, start_response):

        raise ValueError('Value Error')

        return self.wsgi(environ, start_response)

So my issue is when I raise ValueError exception inside Middleware (raise ValueError('Value Error') the @app.errorhandler(ValueError) is not triggering thus I'm not receiving print('Error Catched!') in my console

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Hello again my friend 😉

I told you that Middlewares is out of app layer(outside of the request / outside of the Flask application etc) => application error handler will not work. Just move your logic into @app.before_request or app.before_request_funcs

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda