Open-Assistant icon indicating copy to clipboard operation
Open-Assistant copied to clipboard

Add `OasstError` exception class and corresponding exception filter

Open andreaskoepf opened this issue 2 years ago • 0 comments

This PR introduces the exception class OasstError that can always be used to signal a backend error to the API client with message and open-assistant error_code. It should not be used when the message could leak security relevant information. OasstError is 'picklable'.

The ctor of OasstError takes parameters message: str, error_code: int, http_status_code: int = HTTP_400_BAD_REQUEST. The error-code is a numeric reference to the specific error-site in the backend.

An exception handler is registered which generates a json response with message and error_code (using a http-status code as specified by the OasstError class).

Resolves #55

andreaskoepf avatar Dec 28 '22 13:12 andreaskoepf