Skip to main content

15.1.7 Error Handling

Exception Type

The SDK wraps all API errors in a single ApiException class. You can retrieve the HTTP status code and the server-side error message from it.

import org.openapitools.client.ApiException;

try {
ElementDTO element = elementApi.apiV1ElementsIdGet("nonexistent-id");
} catch (ApiException e) {
System.err.println("HTTP status: " + e.getCode());
System.err.println("Error message: " + e.getMessage());
System.err.println("Response body: " + e.getResponseBody());
}

Common Error Codes

HTTP StatusMeaningCommon CauseRecommended Action
400Bad requestWrong parameter type or missing required fieldCheck request parameters
401UnauthenticatedToken missing or expiredRe-authenticate and obtain a new token
403ForbiddenCurrent user has no permission for this resourceReview user role and element access configuration
404Not foundWrong ID or resource has been deletedVerify the resource ID
429Too many requestsAPI rate limit exceededReduce request frequency; add retry with backoff
500Internal server errorServer-side exceptionRetry later, or contact the administrator

For 429 (rate limiting) and 5xx (server errors), use exponential backoff:

import time
from idmp_sdk.rest import ApiException

def call_with_retry(fn, max_retries=3, base_delay=1.0):
"""
Retry wrapper with exponential backoff.
Retries on 429 and 5xx errors only; raises immediately on 4xx client errors.
"""
for attempt in range(max_retries):
try:
return fn()
except ApiException as e:
if e.status == 429 or e.status >= 500:
if attempt == max_retries - 1:
raise
wait = base_delay * (2 ** attempt) # 1s, 2s, 4s...
print(f"Request failed ({e.status}), retrying in {wait}s...")
time.sleep(wait)
else:
raise # 4xx errors are not retried

# Usage
result = call_with_retry(
lambda: element_api.api_v1_elements_get(page_num=1, page_size=50)
)

Debugging Tips

  • On 401, check first whether the token has expired — do not assume a code bug.
  • On 400, print the full responseBody. The server typically includes a specific description of which parameter is invalid.
  • During development, enable HTTP request logging in the SDK to trace the raw request and response.