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

Method handle_errors

python/ccxt/async_support/whitebit.py:3948–3997  ·  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

3946 return {'url': url, 'method': method, 'body': body, 'headers': headers}
3947
3948 def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
3949 if (code == 418) or (code == 429):
3950 raise DDoSProtection(self.id + ' ' + str(code) + ' ' + reason + ' ' + body)
3951 if code == 404:
3952 raise ExchangeError(self.id + ' ' + str(code) + ' endpoint not found')
3953 if response is not None:
3954 # For cases where we have a meaningful status
3955 # {"response":null,"status":422,"errors":{"orderId":["Finished order id 435453454535 not found on your account"]},"notification":null,"warning":"Finished order id 435453454535 not found on your account","_token":null}
3956 status = self.safe_string(response, 'status')
3957 errors = self.safe_value(response, 'errors')
3958 # {"code":10,"message":"Unauthorized request."}
3959 message = self.safe_string(response, 'message')
3960 # For these cases where we have a generic code variable error key
3961 # {"code":0,"message":"Validation failed","errors":{"amount":["Amount must be greater than 0"]}}
3962 codeNew = self.safe_integer(response, 'code')
3963 hasErrorStatus = status is not None and status != '200' and errors is not None
3964 if hasErrorStatus or codeNew is not None:
3965 feedback = self.id + ' ' + body
3966 errorInfo = message
3967 if hasErrorStatus:
3968 errorInfo = status
3969 else:
3970 errorObject = self.safe_dict(response, 'errors', {})
3971 errorKeys = list(errorObject.keys())
3972 errorsLength = len(errorKeys)
3973 if errorsLength > 0:
3974 errorKey = errorKeys[0]
3975 errorMessageArray = self.safe_value(errorObject, errorKey, [])
3976 errorMessageLength = len(errorMessageArray)
3977 errorInfo = errorMessageArray[0] if (errorMessageLength > 0) else body
3978 self.throw_exactly_matched_exception(self.exceptions['exact'], errorInfo, feedback)
3979 self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
3980 raise ExchangeError(feedback)
3981 # {"success":false,"message":{"limit":["limit must be less than or equal to 100"]},"result":null}
3982 success = self.safe_bool(response, 'success', True)
3983 if not success:
3984 errMsg = self.safe_dict(response, 'message', {})
3985 errKeys = list(errMsg.keys())
3986 errKeysLength = len(errKeys)
3987 errorInfo = body
3988 if errKeysLength > 0:
3989 errorKey = errKeys[0]
3990 errorMessageArray = self.safe_list(errMsg, errorKey, [])
3991 errorMessageLength = len(errorMessageArray)
3992 errorInfo = errorMessageArray[0] if (errorMessageLength > 0) else body
3993 feedback = self.id + ' ' + body
3994 self.throw_exactly_matched_exception(self.exceptions['exact'], errorInfo, feedback)
3995 self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
3996 raise ExchangeError(feedback)
3997 return None

Callers

nothing calls this directly

Calls 10

DDoSProtectionClass · 0.90
ExchangeErrorClass · 0.90
safe_stringMethod · 0.80
safe_valueMethod · 0.80
safe_integerMethod · 0.80
safe_dictMethod · 0.80
safe_boolMethod · 0.80
safe_listMethod · 0.80

Tested by

no test coverage detected