/
urusai
/
code_sample
Обзор
Документация
Войти
/
urusai
/
code_sample
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/exceptions/db/exceptions.py
48 строк
1 KB
nick
init
30 сен 2024, 16:12
30 сен 2024, 16:12
c68451c
Код
Авторство
О чём код?
from typing import Optional from sqlalchemy.exc import DatabaseError class ExceptionSQLError(Exception): def __init__( self, detail: str, code: int, sql_detail: Optional[str] = None, exc: Optional[DatabaseError] = None, ): self.code = code self.detail = detail self.sql_detail = sql_detail self._exc = exc @property def original_exception(self): if isinstance(self._exc, DatabaseError): return self._exc.orig.__cause__ else: return self._exc @property def original_message(self): return getattr(self.original_exception, "message", None) @property def original_detail(self): return getattr(self.original_exception, "detail", None) class NotFoundError(ExceptionSQLError): def __init__( self, detail: str, code: int, sql_detail: Optional[str] = None, exc: Optional[DatabaseError] = None, ): super(NotFoundError, self).__init__( detail=detail, code=code, sql_detail=sql_detail, exc=exc, )