Implement task API with input validation; implement error handling; refactoring
This commit is contained in:
parent
19d264a03b
commit
50aff05614
24 changed files with 612 additions and 131 deletions
30
tofu_api/common/rest/exceptions.py
Normal file
30
tofu_api/common/rest/exceptions.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
__all__ = [
|
||||
'InternalServerError'
|
||||
]
|
||||
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from tofu_api.common.exceptions import AppException
|
||||
|
||||
|
||||
class InternalServerError(AppException):
|
||||
"""
|
||||
Wrapper exception for any uncaught exception.
|
||||
"""
|
||||
status_code = 500
|
||||
code = 'internal_server_error'
|
||||
inner_exception: Optional[Exception] = None
|
||||
|
||||
def __init__(self, message: str, *, inner_exception: Optional[Exception] = None):
|
||||
super().__init__(message)
|
||||
self.inner_exception = inner_exception
|
||||
|
||||
def to_dict(self, *, debug: bool = False) -> dict:
|
||||
data = super().to_dict()
|
||||
if debug:
|
||||
data['_debug'] = {
|
||||
'exception': str(self.inner_exception),
|
||||
'traceback': traceback.format_exception(self.inner_exception),
|
||||
}
|
||||
return data
|
||||
Loading…
Add table
Add a link
Reference in a new issue