A journey to fix `ValidationError` in Pocket imports turned service layer refactoring :D
29 lines
702 B
Python
29 lines
702 B
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import typing
|
|
|
|
from .backend import BackendServiceError
|
|
|
|
|
|
class SOAError(Exception):
|
|
def __init__(self, code: int, message: str, *args):
|
|
super().__init__(code, message, *args)
|
|
self.code = code
|
|
self.message = message
|
|
|
|
self.data: typing.Any = None
|
|
if len(args) > 0:
|
|
self.data = args[0]
|
|
|
|
@classmethod
|
|
def from_backend_error(cls: type[typing.Self], exception: BackendServiceError) -> typing.Self:
|
|
result = cls(
|
|
exception.CODE.value,
|
|
exception.message,
|
|
exception.data,
|
|
)
|
|
result.__cause__ = exception
|
|
|
|
return result
|