# -*- coding: utf-8 -*-
from __future__ import annotations

import typing


class SOAError(Exception):
    pass


class Service:
    def wrap_exception(self, exception: Exception) -> Exception:
        return SOAError(exception.args[0])


class ProxyService(Service):
    def call(self, service: typing.Any, method: str, *args, **kwargs) -> typing.Any:
        handler = getattr(service, method, None)
        assert handler is not None, f'Unknown method: method=`{method}`'

        try:
            return handler(*args, **kwargs)
        except Exception as exception:
            raise self.wrap_exception(exception) from exception
