tofu-api/tofu_api/common/rest/exceptions.py

31 lines
828 B
Python

__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