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

Method handle_errors

python/ccxt/async_support/cex.py:1722–1747  ·  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

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