Skip to content

Commit

Permalink
Merge pull request #180 from ral-facilities/feature/fix-exception-han…
Browse files Browse the repository at this point in the history
…dling-#147

Fix Exception Handling for Non-Debug Mode
  • Loading branch information
MRichards99 authored Dec 2, 2020
2 parents 5125106 + 511a8ef commit b12e7cd
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 b12e7cd

Please sign in to comment.