import sys
import traceback

from ._DataType import DataType
from ._DefaultToken import DefaultToken
from ._Message import Message


class InternalErrorMessage(Message):
    def __init__(
        self,
        ex,    # type: Exception
    ):
        tb = sys.exc_info()[2]
        exception_messages = traceback.format_exception(type(ex), ex, tb)
        super(InternalErrorMessage, self).__init__(
            token=DefaultToken.TK_SYS_NAK,
            data_type=DataType.string,
            data="".join(exception_messages).encode("utf-8"),
        )
