|
15 | 15 | from module_admin.service.login_service import LoginService |
16 | 16 | from config.enums import BusinessType |
17 | 17 | from config.env import AppConfig |
| 18 | +from exceptions.exception import LoginException, ServiceException, ServiceWarning |
| 19 | +from utils.response_util import ResponseUtil |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class Log: |
@@ -111,8 +113,17 @@ async def wrapper(*args, **kwargs): |
111 | 113 | loginTime=oper_time.strftime('%Y-%m-%d %H:%M:%S'), |
112 | 114 | ) |
113 | 115 | kwargs['form_data'].login_info = login_log |
114 | | - # 调用原始函数 |
115 | | - result = await func(*args, **kwargs) |
| 116 | + try: |
| 117 | + # 调用原始函数 |
| 118 | + result = await func(*args, **kwargs) |
| 119 | + except LoginException as e: |
| 120 | + result = ResponseUtil.failure(data=e.data, msg=e.message) |
| 121 | + except ServiceException as e: |
| 122 | + result = ResponseUtil.error(data=e.data, msg=e.message) |
| 123 | + except ServiceWarning as e: |
| 124 | + result = ResponseUtil.failure(data=e.data, msg=e.message) |
| 125 | + except Exception as e: |
| 126 | + result = ResponseUtil.error(msg=str(e)) |
116 | 127 | # 获取请求耗时 |
117 | 128 | cost_time = float(time.time() - start_time) * 100 |
118 | 129 | # 判断请求是否来自api文档 |
@@ -281,8 +292,17 @@ async def wrapper(*args, **kwargs): |
281 | 292 | loginTime=oper_time.strftime('%Y-%m-%d %H:%M:%S'), |
282 | 293 | ) |
283 | 294 | kwargs['form_data'].login_info = login_log |
284 | | - # 调用原始函数 |
285 | | - result = await func(*args, **kwargs) |
| 295 | + try: |
| 296 | + # 调用原始函数 |
| 297 | + result = await func(*args, **kwargs) |
| 298 | + except LoginException as e: |
| 299 | + result = ResponseUtil.failure(data=e.data, msg=e.message) |
| 300 | + except ServiceException as e: |
| 301 | + result = ResponseUtil.error(data=e.data, msg=e.message) |
| 302 | + except ServiceWarning as e: |
| 303 | + result = ResponseUtil.failure(data=e.data, msg=e.message) |
| 304 | + except Exception as e: |
| 305 | + result = ResponseUtil.error(msg=str(e)) |
286 | 306 | # 获取请求耗时 |
287 | 307 | cost_time = float(time.time() - start_time) * 100 |
288 | 308 | # 判断请求是否来自api文档 |
|
0 commit comments