Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unhandled exception handling blocks. #5933

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

Aadesh-Baral
Copy link
Contributor

@Aadesh-Baral Aadesh-Baral commented Jun 22, 2023

Part of #5912
As all of the unhandled errors will be now captured and processed by flask errorhandler defined on #5909, we no longer have to handle them manually using try except blocks. This PR removes these blocks that were set to handle these unhandled exceptions.

@app.errorhandler(Exception)
def handle_generic_error(error):
"""Generic error handler for all exceptions"""
from backend.exceptions import format_sub_code
app.logger.exception(error)
error_message = (
str(error)
if len(str(error)) > 0
else ERROR_MESSAGES["INTERNAL_SERVER_ERROR"]
)
error_code = error.code if hasattr(error, "code") else 500
error_sub_code = (
format_sub_code(error.name)
if hasattr(error, "name")
else "INTERNAL_SERVER_ERROR"
)
return (
{
"error": {
"code": error_code,
"sub_code": error_sub_code,
"message": error_message,
"details": {
"url": request.url,
"method": request.method,
},
}
},
error_code,
)

@Aadesh-Baral Aadesh-Baral force-pushed the dev/remove-generic-exception-handler-blocks branch 2 times, most recently from 722360a to d7917ae Compare June 22, 2023 05:33
-----------------------------------
As all of the unhandled errors will be now captured and processed by
flask errorhandler defined on [link](https://github.com/hotosm/tasking-manager/blob/9582691a4ac2acc8a50b94deae82dd2a97ae7fa7/backend/__init__.py#L116-L147).
Due to this we no longer have to handle them manyally using try except blocks. This commit removes these blocks that were set to hanlde these unhandled exceptions.
@Aadesh-Baral Aadesh-Baral force-pushed the dev/remove-generic-exception-handler-blocks branch from d7917ae to e9b55a8 Compare June 22, 2023 06:03
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@d-rita d-rita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested endpoints via the swagger docs. Endpoints work fine. Odd cases that stood out were not related to this implementation. LGTM.

@Aadesh-Baral Aadesh-Baral merged commit 99412a2 into develop Jul 17, 2023
@Aadesh-Baral Aadesh-Baral deleted the dev/remove-generic-exception-handler-blocks branch July 17, 2023 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants