All exceptions raised by the SDK inherit from RSGeError, making it easy to catch any SDK-specific error in a single handler. Import them directly from rsge:
from rsge import (
RSGeError,
RSGeAuthenticationError,
RSGeValidationError,
RSGeAPIError,
RSGeConnectionError,
)Source: rsge/core/exceptions.py
Exception
└── RSGeError
├── RSGeAuthenticationError
├── RSGeValidationError
├── RSGeAPIError
├── RSGeConnectionError
└── RSGePermissionError
Base exception for all RS.ge SDK errors.
| Attribute | Type | Description |
|---|---|---|
message |
str |
Human-readable error description |
code |
int | None |
Optional numeric error code from the RS.ge API |
try:
result = client.save_waybill(waybill)
except RSGeError as exc:
print(f'Error: {exc.message}')
if exc.code is not None:
print(f'Code: {exc.code}')Raised when authentication with the RS.ge service fails. Common causes:
- Invalid service username or password
- Expired or missing credentials
- Customs API called without authenticating first
try:
client.check_service_user()
except RSGeAuthenticationError:
print('Invalid credentials')Known error codes:
-100— Invalid service credentials
Raised when input data fails validation before being sent to the API.
Raised when the RS.ge API returns a business-logic error (negative error codes). This is the most common error type during normal operations.
try:
client.close_waybill(waybill_id)
except RSGeAPIError as exc:
print(f'API error {exc.code}: {exc.message}')Raised when the SDK cannot reach the RS.ge servers. Common causes:
- Network connectivity issues
- DNS resolution failure
- RS.ge service downtime
try:
client.check_service_user()
except RSGeConnectionError:
print('Cannot reach RS.ge servers')Raised when the user lacks permission for the requested operation.
Known error codes:
-101— Cannot modify another user's waybill
from rsge import RSGeError
try:
result = client.save_waybill(waybill)
except RSGeError as exc:
print(f'SDK error: {exc.message}')from rsge import (
RSGeAuthenticationError,
RSGeAPIError,
RSGeConnectionError,
)
try:
client.check_service_user()
result = client.save_waybill(waybill)
client.activate_waybill(result.waybill_id)
except RSGeAuthenticationError:
print('Check your credentials')
except RSGeConnectionError:
print('Network error, retrying...')
except RSGeAPIError as exc:
print(f'Business error {exc.code}: {exc.message}')The RS.ge API provides a list of all error codes and descriptions:
error_codes = client.get_error_codes()
for ec in error_codes:
print(f'{ec.id}: {ec.text} (type={ec.error_type})')Error types: 1 = waybill error, 2 = goods item error, 3 = invoice error.