(*args, **kwargs)
| 27 | """装饰器 |
| 28 | """ |
| 29 | def __deco(*args, **kwargs): |
| 30 | rsp = func(*args, **kwargs) |
| 31 | result = rsp.data.decode("utf-8") |
| 32 | # 正常返回 |
| 33 | if 200 <= rsp.status < 300: |
| 34 | if result: |
| 35 | return json.loads(result) |
| 36 | else: |
| 37 | return result |
| 38 | else: |
| 39 | # 其他错误,如请求参数错误 |
| 40 | logger.error(result) |
| 41 | # 系统错误 |
| 42 | if rsp.status >= 500: |
| 43 | raise CDErrorBase(errcode.E_SERVER, "server return code[%d] %s with params %s" % ( |
| 44 | rsp.status, result, str(args))) |
| 45 | else: |
| 46 | raise CDErrorBase(errcode.E_CLIENT, "server return code[%d] %s with params %s" % ( |
| 47 | rsp.status, result, str(args)), data=result) |
| 48 | |
| 49 | return __deco |
| 50 |
nothing calls this directly
no test coverage detected