Skip to content

Missing Error codes On raised exceptions #460

@barkin-kaplan

Description

@barkin-kaplan

This is a snippet taken from send_request function which resides under binance_common/utils.py. Error codes from api aren't passed to the raised exception. Only verbal explanations are passed and since verbal explanations are subject to change, writing control flows against them can cause issues for running trading bots or algorithms. I suggest that error_code field is added to each raised error and inside the send_request function, related error_code is taken from the response and passed into these errors.

if status == 400:
    raise BadRequestError(error_message=data.get("msg"))
elif status == 401:
    raise UnauthorizedError(error_message=data.get("msg"))
elif status == 403:
    raise ForbiddenError(error_message=data.get("msg"))
elif status == 404:
    raise NotFoundError(error_message=data.get("msg"))
elif status == 418:
    raise RateLimitBanError(error_message=data.get("msg"))
elif status == 429:
    raise TooManyRequestsError(error_message=data.get("msg"))
elif 500 <= status < 600:
    raise ServerError(
        error_message=f"Server error: {status}", status_code=status
    )
else:
    raise ClientError(error_message=data.get("msg"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions