
class AerospikeRestApiError(Exception):
    def __init__(self, http_response, status_code):
        self.message = http_response['message']
        self.in_doubt = http_response['inDoubt']
        self.status_code = status_code
        self.code = http_response['internalErrorCode']
    
    def __str__(self):
        return "{} {}".format(self.status_code, self.message)


# error codes from Java client:
# https://github.com/aerospike/aerospike-client-java/blob/master/client/src/com/aerospike/client/ResultCode.java

SERIALIZE_ERROR = -10
ASYNC_QUEUE_FULL = -9
SERVER_NOT_AVAILABLE = -8
NO_MORE_CONNECTIONS = -7
COMMAND_REJECTED = -6
QUERY_TERMINATED = -5
SCAN_TERMINATED = -4
INVALID_NODE_ERROR = -3
PARSE_ERROR = -2
CLIENT_ERROR = -1
OK = 0
SERVER_ERROR = 1
KEY_NOT_FOUND_ERROR = 2
GENERATION_ERROR = 3
PARAMETER_ERROR = 4
KEY_EXISTS_ERROR = 5
BIN_EXISTS_ERROR = 6
CLUSTER_KEY_MISMATCH = 7
SERVER_MEM_ERROR = 8
TIMEOUT = 9
ALWAYS_FORBIDDEN = 10
PARTITION_UNAVAILABLE = 11
BIN_TYPE_ERROR = 12
RECORD_TOO_BIG = 13
KEY_BUSY = 14
SCAN_ABORT = 15
UNSUPPORTED_FEATURE = 16
BIN_NOT_FOUND = 17
DEVICE_OVERLOAD = 18
KEY_MISMATCH = 19
INVALID_NAMESPACE = 20
BIN_NAME_TOO_LONG = 21
FAIL_FORBIDDEN = 22
ELEMENT_NOT_FOUND = 23
ELEMENT_EXISTS = 24
ENTERPRISE_ONLY = 25
OP_NOT_APPLICABLE = 26
FILTERED_OUT = 27
QUERY_END = 50
SECURITY_NOT_SUPPORTED = 51
SECURITY_NOT_ENABLED = 52
SECURITY_SCHEME_NOT_SUPPORTED = 53
INVALID_COMMAND = 54
INVALID_FIELD = 55
ILLEGAL_STATE = 56
INVALID_USER = 60
USER_ALREADY_EXISTS = 61
INVALID_PASSWORD = 62
EXPIRED_PASSWORD = 63
FORBIDDEN_PASSWORD = 64
INVALID_CREDENTIAL = 65
EXPIRED_SESSION = 66
INVALID_ROLE = 70
ROLE_ALREADY_EXISTS = 71
INVALID_PRIVILEGE = 72
INVALID_WHITELIST = 73
NOT_AUTHENTICATED = 80
ROLE_VIOLATION = 81
NOT_WHITELISTED = 82
UDF_BAD_RESPONSE = 100
BATCH_DISABLED = 150
BATCH_MAX_REQUESTS_EXCEEDED = 151
BATCH_QUEUES_FULL = 152
INDEX_ALREADY_EXISTS = 200
INDEX_FOUND = 200
INDEX_NOTFOUND = 201
INDEX_OOM = 202
INDEX_NOTREADABLE = 203
INDEX_GENERIC = 204
INDEX_NAME_MAXLEN = 205
INDEX_MAXCOUNT = 206
QUERY_ABORTED = 210
QUERY_QUEUEFULL = 211
QUERY_TIMEOUT = 212
QUERY_GENERIC = 213
