Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!