MCPcopy Create free account
hub / github.com/ccxt/ccxt / handle_errors

Method handle_errors

python/ccxt/cex.py:1721–1746  ·  view source on GitHub ↗
(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody)

Source from the content-addressed store, hash-verified

1719 return {'url': url, 'method': method, 'body': body, 'headers': headers}
1720
1721 def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
1722 # in some cases, like from createOrder, exchange returns nested escaped JSON string:
1723 # {"ok":"ok","data":{"messageType":"executionReport", "orderRejectReason":"{\"code\":405}"}}
1724 # and because of `.parseJson` bug, we need extra fix
1725 if response is None:
1726 if body is None:
1727 raise NullResponse(self.id + ' returned empty response')
1728 elif body[0] == '{':
1729 fixed = self.fix_stringified_json_members(body)
1730 response = self.parse_json(fixed)
1731 else:
1732 raise NullResponse(self.id + ' returned unparsed response: ' + body)
1733 error = self.safe_string(response, 'error')
1734 if error is not None:
1735 feedback = self.id + ' ' + body
1736 self.throw_exactly_matched_exception(self.exceptions['exact'], error, feedback)
1737 self.throw_broadly_matched_exception(self.exceptions['broad'], error, feedback)
1738 raise ExchangeError(feedback)
1739 # check errors in order-engine(the responses are not standard, so we parse here)
1740 if url.find('do_my_new_order') >= 0:
1741 data = self.safe_dict(response, 'data', {})
1742 rejectReason = self.safe_string(data, 'rejectReason')
1743 if rejectReason is not None:
1744 self.throw_broadly_matched_exception(self.exceptions['broad'], rejectReason, rejectReason)
1745 raise ExchangeError(self.id + ' createOrder() ' + rejectReason)
1746 return None

Callers

nothing calls this directly

Calls 9

NullResponseClass · 0.90
ExchangeErrorClass · 0.90
parse_jsonMethod · 0.80
safe_stringMethod · 0.80
findMethod · 0.80
safe_dictMethod · 0.80

Tested by

no test coverage detected