# -*- coding: utf-8 -*- # !/usr/bin/env python from apps.web.constant import ErrorCode class ApiException(Exception): def __init__(self, errcode, errmsg, payload = {}): self.errcode = errcode self.payload = payload self.errmsg = errmsg def __repr__(self): return 'api exception. errcode = {}, errmsg = {}, payload = {}'.format( self.errcode, self.errmsg, str(self.payload)) def __str__(self): return self.__repr__() def to_response(self): from apps.web.api.utils import api_error_response return api_error_response(errcode = self.errcode, errmsg = self.errmsg, payload = self.payload) class ApiParameterError(ApiException): def __init__(self, errmsg): super(ApiParameterError, self).__init__( errcode = ErrorCode.API_PARAMETER_ERROR, errmsg = errmsg) class ApiAuthException(ApiException): def __init__(self, errmsg): super(ApiAuthException, self).__init__( errcode = ErrorCode.API_AUTH_ERROR, errmsg = errmsg, payload = {'auth_result': 1}) class ApiAuthDeviceException(ApiException): def __init__(self): super(ApiAuthDeviceException, self).__init__( errcode = ErrorCode.API_AUTH_DEVICE_ERROR, errmsg = u'无权操作设备', payload = {'auth_result': 3}) class ApiNoDeviceException(ApiException): def __init__(self): super(ApiNoDeviceException, self).__init__( errcode = ErrorCode.API_NO_DEVICE, errmsg = u'设备不存在') class ApiDeviceModeException(ApiException): def __init__(self): super(ApiDeviceModeException, self).__init__( errcode = ErrorCode.API_NO_DEVICE, errmsg = u'当前设备不在API模式, 请切换API模式(经销商后台->API接口管理->API设备管理)') class ApiDeviceTypeError(ApiException): def __init__(self, errmsg): super(ApiDeviceTypeError, self).__init__( errcode = ErrorCode.API_ERROR_DEVICE_TYPE, errmsg = errmsg)