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

Improve Error Handling in REST Interface #92

Closed
soad003 opened this issue Apr 21, 2023 · 1 comment
Closed

Improve Error Handling in REST Interface #92

soad003 opened this issue Apr 21, 2023 · 1 comment
Assignees

Comments

@soad003
Copy link
Member

soad003 commented Apr 21, 2023

Global error handling is currently done in the auto generated (via a template) controllers where uncatched errors are converted into http responses (e.g.

except RuntimeError as e:
traceback.print_exception(type(e), e, e.__traceback__)
raise web.HTTPNotFound(text=str(e))
except ValueError as e:
traceback.print_exception(type(e), e, e.__traceback__)
raise web.HTTPBadRequest(text=str(e))
except Exception as e:
tb = traceback.format_exception(type(e), e, e.__traceback__)
tb.append(f"Request URL: {request.url}")
tb = "\n".join(tb)
request.app.logger.error(tb)
raise web.HTTPInternalServerError()
async def get_address_entity(request: web.Request, currency, address) -> web.Response:
"""Get the entity of an address
).

Some exception types get special treatment like value errors and Runtime errors. They are simply ignored and a generic http status code is returned to the client. Only a stacktrace is printed to the console log and no other notifications are set up. Given that we only get notified on error logs via the python logging facility those kinds of errors usually go unnoticed.

@soad003
Copy link
Member Author

soad003 commented Sep 15, 2023

The old logic reused generic exception types for signaling very specific events to the user:

  • RuntimeErrors where used to signal some item was not found.
  • ValueErrors where uses to signal wrong user input

Since these exception types are very generic and used by libs etc. in an uncontrollable fashion, some errors gone unnoticed (where only reported to the user). As a remedy we introduced new custom exceptions to handle the two exception cases we want to explicitly push back to the user.

  • NotFoundException signals some app logic item was not found
  • BadUserInputException is used to signal to users that the input was wrong.

This should avoid missing relevant errors in the REST interface.

@soad003 soad003 closed this as completed Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants