# -*- coding: utf-8 -*- # !/usr/bin/env python from __future__ import absolute_import, unicode_literals import six from typing import Optional from library import to_binary, to_text from .base import DlbErrorCode class DlbException(Exception): def __init__(self, errorCode, errorMsg, client = None, request = None, response = None): self.errCode = errorCode self.errMsg = errorMsg self.client = client self.request = request self.response = response super(DlbException, self).__init__(errorMsg) def __str__(self): if self.client: _repr = '{kclass}(client: {client}, errCode: {errCode}, errMsg: {errMsg})'.format( kclass = self.__class__.__name__, client = repr(self.client), errCode = self.errCode, errMsg = self.errMsg) else: _repr = '{kclass}(errCode: {errCode}, errMsg: {errMsg})'.format( kclass = self.__class__.__name__, errCode = self.errCode, errMsg = self.errMsg) if six.PY2: return to_binary(_repr) else: return to_text(_repr) def __repr__(self): return str(self) class DlbPayException(DlbException): pass class DlbValidationError(DlbException): def __init__(self, errmsg, lvalue, rvalue, client = None): # type: (basestring, basestring, basestring, Optional[object])->None super(DlbValidationError, self).__init__( errorCode = str(DlbErrorCode.MY_VALID_ERROR), errorMsg = '{}({} != {})'.format(errmsg, lvalue, rvalue), client = client)