hashtopolis/server

[ENHANCEMENT]: Refactor Exception Handling to Use specific Exception Types for Better Error differentiation.

Opened this issue · 1 comments

Description

Currently the project only makes use of HTException as a very general exception for all error cases. This makes it challenging to handle different errors appropriately. Especially if we want to adhere to the JSON API standard it is helpful if more specific Exceptions get throwed so that the API can catch these specific exceptions and respond with appropriate HTTP status codes and responses.

Tasks:

  • Define and implement specific exception classes for common error scenario ex: conflict, field missing ....
  • Refactor service and logic layers to throw the new exceptions
  • Update the new API to catch specific exceptions and return the proper HTTP responses
  • Add documentation for the new exception handling

We usually define a base exception class, e.g. ApplicationException and derive all other exceptions from this base class, lets say DBFieldErrorException, InvalidTypeException and so on. Each exception contains its own error message and/or a status code.

The surrounding API does not know, which exact exceptions could be thrown, it always catches ApplicationExcetion, but gets the error message and error code from the real exception class.

Maybe we could define a similar exception system, just share your thoughts ;-)