Skip to main content

Error Handling

Exception Type

All API errors are wrapped in ApiException. You can extract the HTTP status code and server 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("Message: " + e.getMessage());
System.err.println("Response body: " + e.getResponseBody());
}

Common Error Codes

HTTP StatusMeaningCommon CauseRecommended Action
400Bad RequestInvalid parameter type, missing required fieldCheck request parameters
401UnauthorizedToken missing or expiredRe-authenticate and get a new token
403ForbiddenCurrent user lacks permissionCheck user permissions in IDMP
404Not FoundWrong ID, or resource was deletedVerify the resource ID
429Too Many RequestsRate limit exceededBack off and retry with exponential delay
500Internal Server ErrorServer-side exceptionRetry later or contact the administrator

Retry Pattern (Exponential Backoff)

Use exponential backoff for 429 and 5xx errors. Do not retry 4xx (client errors).

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 only; raises immediately on 4xx.
"""
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: don't retry

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

Debugging Tips

  • On 401: check whether the token has expired before looking at your code logic
  • On 400: print the full responseBody — the server usually specifies exactly which parameter is invalid
  • During development, enable HTTP request logging in the SDK to inspect raw requests and responses