Skip to content

Commit

Permalink
Fix error handling regression from connexion upgrade (#1160)
Browse files Browse the repository at this point in the history
spec-first/connexion#1326 changed
FlaskApp.common_error_handler from a static method to a regular method, which
means we can't use it without an actual FlaskApp, or we'd turn any error
into a TypeError and 500.

Fixes #1159
  • Loading branch information
jcristau authored Dec 20, 2023
1 parent d5b08b3 commit 168943f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 0 additions & 10 deletions api/src/tooltool_api/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ def __init__(self, app):
"""
self.__app = app

logger.debug("Setting JSON encoder.")
app.json_encoder = FlaskJSONEncoder

logger.debug("Setting common error handler for all error codes.")
# FlaskApp sets up error handler automatically, but FlaskApi doesn't.
# We have to set them up manually.
for error_code in default_exceptions:
app.register_error_handler(error_code, FlaskApp.common_error_handler)

app.register_error_handler(ProblemException, FlaskApp.common_error_handler)

def register(
self,
Expand Down
4 changes: 3 additions & 1 deletion api/src/tooltool_api/lib/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import importlib
import os

import connexion
import flask

import tooltool_api.lib.dockerflow
Expand All @@ -24,7 +25,8 @@ def create_app(project_name, extensions=[], config=None, enable_dockerflow=True,
"""
logger.debug("Initializing", app=project_name)

app = flask.Flask(import_name=project_name, **kw)
connexion_app = connexion.FlaskApp(import_name=project_name, server_args=kw)
app = connexion_app.app
app.name = project_name
app.__extensions = extensions

Expand Down

0 comments on commit 168943f

Please sign in to comment.