import json
from abc import (
    ABCMeta,
    abstractmethod,
)
from typing import (
    Any,
    Dict,
)


class TableError(Exception):
    __metaclass__ = ABCMeta

    error_code = -1

    @property
    def error_message(self):
        # type: (...) -> str

        ex_dict = {
            "ex": self.__class__.__name__,
        }
        extra_data = self.get_extra_data()
        if extra_data is not None:
            ex_dict.update(extra_data)

        return json.dumps(ex_dict)

    @abstractmethod
    def get_extra_data(self):
        # type: (...) -> Dict[str, Any]

        raise NotImplementedError()
