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

320
Views
In Flask is there a way to handle all the type of errors with one error handler & return the type of error occurred?

Is there anyway to handle all the type of error with one definition & return the type of error occurred , For example in the below code error handeller is there for 404 but if I am unaware of other possible errors how can I print the error on html page

from flask import Flask, abort
app = Flask(__name__)

@app.route("/")
def hello():
    return "Welcome to Python Flask."

@app.errorhandler(404) 
def invalid_route(e): 
    return "Invalid route."

Expected if possible

@app.errorhandler(Type of error) #is there anything I can user here ?
def invalid_route(e): 
    return f"Type of error occurred is {e}"
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yea there are generic exception handlers

from flask import Flask
from werkzeug.exceptions import HTTPException

app = Flask(__name__)


@app.route("/")
def hello():
    return "Welcome to Python Flask."


@app.errorhandler(HTTPException)
def handle_exception(e):
    return f'Type of error occurred is {e.code}'

app.run()

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!