mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-03 16:35:10 +00:00
perf: 补充cmpp2翻译及部分报错提示 (#8717)
* 修改CMPPv2.0翻译内容 * perf: 捕捉连接网关出错问题 * perf: 测试短信验证失败提示错误信息 * perf: 修改翻译
This commit is contained in:
@@ -4,6 +4,7 @@ import struct
|
||||
import time
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.utils import get_logger
|
||||
from common.exceptions import JMSException
|
||||
@@ -42,7 +43,7 @@ class CMPPBaseRequestInstance(object):
|
||||
class CMPPConnectRequestInstance(CMPPBaseRequestInstance):
|
||||
def __init__(self, sp_id, sp_secret):
|
||||
if len(sp_id) != 6:
|
||||
raise ValueError("sp_id and sp_secret are both 6 bits")
|
||||
raise ValueError(_("sp_id is 6 bits"))
|
||||
|
||||
super().__init__()
|
||||
|
||||
@@ -212,14 +213,19 @@ class CMPPClient(object):
|
||||
|
||||
def _connect(self):
|
||||
self.__socket.settimeout(5)
|
||||
error_msg = _('Failed to connect to the CMPP gateway server, err: {}')
|
||||
for i in range(self._times):
|
||||
try:
|
||||
self.__socket.connect((self.ip, self.port))
|
||||
except socket.timeout:
|
||||
except Exception as err:
|
||||
error_msg = error_msg.format(str(err))
|
||||
logger.warning(error_msg)
|
||||
time.sleep(1)
|
||||
else:
|
||||
self._is_connect = True
|
||||
break
|
||||
else:
|
||||
raise JMSException(error_msg)
|
||||
|
||||
def send(self, instance):
|
||||
if isinstance(instance, CMPPBaseRequestInstance):
|
||||
@@ -299,9 +305,10 @@ class CMPP2SMS(BaseSMSClient):
|
||||
self.client = CMPPClient(
|
||||
host=host, port=port, sp_id=sp_id, sp_secret=sp_secret, src_id=src_id, service_id=service_id
|
||||
)
|
||||
except socket.timeout:
|
||||
except Exception as err:
|
||||
self.client = None
|
||||
logger.warning('CMPPv2.0 connect remote time out.')
|
||||
logger.warning(err)
|
||||
raise JMSException(err)
|
||||
|
||||
@staticmethod
|
||||
def need_pre_check():
|
||||
|
Reference in New Issue
Block a user