Skip to content

Commit

Permalink
Merge pull request #66 from erev0s/custom_error
Browse files Browse the repository at this point in the history
custom generic error
  • Loading branch information
erev0s authored Nov 25, 2024
2 parents 242c75f + d7f1f93 commit 1713b54
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import connexion
from flask import jsonify
from flask_sqlalchemy import SQLAlchemy
from connexion.exceptions import ProblemException

vuln_app = connexion.App(__name__, specification_dir='./openapi_specs')

Expand All @@ -13,13 +14,14 @@
# start the db
db = SQLAlchemy(vuln_app.app)


@vuln_app.app.errorhandler(401)
def custom_401(error):
# Custom 401 to match the original response sent by Vampi
response = jsonify({"status": "fail", "message": "Invalid token. Please log in again."})
response.status_code = 401
def custom_problem_handler(error):
# Custom error handler for clarity in structure
response = jsonify({
"status": "fail",
"message": getattr(error, "detail", "An error occurred"),
})
response.status_code = error.status
return response

vuln_app.add_error_handler(ProblemException, custom_problem_handler)

vuln_app.add_api('openapi3.yml')

0 comments on commit 1713b54

Please sign in to comment.