Skip to content

Commit

Permalink
#147: Override handle_error on extended Api class
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Oct 23, 2020
1 parent 80943ad commit 511a8ef
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@
security=[{"session_id": []}],
)

app = Flask(__name__)
cors = CORS(app)
app.url_map.strict_slashes = False
api = Api(app)


def handle_error(e):
return str(e), e.status_code
class CustomErrorHandledApi(Api):
"""
This class overrides `handle_error` function from the API class from `flask_restful`
to correctly return response codes and exception messages from uncaught exceptions
"""

def handle_error(self, e):
return str(e), e.status_code

app.register_error_handler(ApiError, handle_error)

app = Flask(__name__)
cors = CORS(app)
app.url_map.strict_slashes = False
api = CustomErrorHandledApi(app)

swaggerui_blueprint = get_swaggerui_blueprint(
"", "/openapi.json", config={"app_name": "DataGateway API OpenAPI Spec"},
Expand Down

0 comments on commit 511a8ef

Please sign in to comment.