Skip to main content

Error Handling with tryCatch

The R SDK uses R’s condition system for error handling. Use tryCatch to handle specific error types:

Error Types

The SDK defines the following error conditions:
omophub_auth_error is also raised whenever the server reports invalid_api_key or missing_api_key, whatever the status. A 403 means the key was accepted but lacks access (for example, a restricted vocabulary), so it has its own class rather than being reported as an invalid key. Input the SDK rejects before sending a request (a non-integer concept_id, an empty query) raises omophub_validation_error too, but without omophub_api_error, since no request was made.
Every HTTP condition also keeps httr2’s classes (httr2_http_404, httr2_http, and httr2_failure for network errors) and the raw response in e$resp. Handlers written against httr2 conditions keep working.

Error Properties

API errors (omophub_api_error and its subclasses) include:
omophub_rate_limit_error also has e$retry_after (seconds, or NULL if the server did not send Retry-After).

Rate Limiting

Handle rate limits with retry logic:
The SDK automatically retries failed requests up to max_retries times (default: 3) with exponential backoff. You typically don’t need to handle transient errors manually.

Connection Errors

Handle network issues:

Best Practices

Catch Specific Errors First

Use withCallingHandlers for Logging

Wrap in a Safe Function

Create a helper function for common error handling: