(self, res, method=None, url=None,
result_processor=None, **kwargs)
| 112 | return result |
| 113 | |
| 114 | def _handle_result(self, res, method=None, url=None, |
| 115 | result_processor=None, **kwargs): |
| 116 | if not isinstance(res, dict): |
| 117 | # Dirty hack around asyncio based AsyncWeChatClient |
| 118 | result = self._decode_result(res) |
| 119 | else: |
| 120 | result = res |
| 121 | |
| 122 | if not isinstance(result, dict): |
| 123 | return result |
| 124 | |
| 125 | if 'base_resp' in result: |
| 126 | # Different response in device APIs. Fuck tencent! |
| 127 | result.update(result.pop('base_resp')) |
| 128 | if 'errcode' in result: |
| 129 | result['errcode'] = int(result['errcode']) |
| 130 | |
| 131 | if 'errcode' in result and result['errcode'] != 0: |
| 132 | errcode = result['errcode'] |
| 133 | errmsg = result.get('errmsg', errcode) |
| 134 | if self.auto_retry and errcode in ( |
| 135 | WeChatErrorCode.INVALID_CREDENTIAL.value, |
| 136 | WeChatErrorCode.INVALID_ACCESS_TOKEN.value, |
| 137 | WeChatErrorCode.EXPIRED_ACCESS_TOKEN.value): |
| 138 | logger.info('Access token expired, fetch a new one and retry request') |
| 139 | self.fetch_access_token() |
| 140 | access_token = self.session.get(self.access_token_key) |
| 141 | kwargs['params']['access_token'] = access_token |
| 142 | return self._request( |
| 143 | method=method, |
| 144 | url_or_endpoint=url, |
| 145 | result_processor=result_processor, |
| 146 | **kwargs |
| 147 | ) |
| 148 | elif errcode == WeChatErrorCode.OUT_OF_API_FREQ_LIMIT.value: |
| 149 | # api freq out of limit |
| 150 | raise APILimitedException( |
| 151 | errcode, |
| 152 | errmsg, |
| 153 | client=self, |
| 154 | request=res.request, |
| 155 | response=res |
| 156 | ) |
| 157 | else: |
| 158 | raise WeChatClientException( |
| 159 | errcode, |
| 160 | errmsg, |
| 161 | client=self, |
| 162 | request=res.request, |
| 163 | response=res |
| 164 | ) |
| 165 | |
| 166 | return result if not result_processor else result_processor(result) |
| 167 | |
| 168 | def get(self, url, **kwargs): |
| 169 | return self._request( |
no test coverage detected