❌ Error Handling
AgentTech SDKs use typed errors and sentinel values for precise error matching.
Error Types
RequestError
Returned for HTTP 4xx/5xx responses from the API.
if (err instanceof PayApiError) {
console.log(`HTTP ${err.statusCode}: ${err.body}`);
}
var reqErr *pay.RequestError
if errors.As(err, &reqErr) {
log.Printf("HTTP %d: %s", reqErr.StatusCode, reqErr.Body)
}
ValidationError
Returned when the SDK rejects a request before it reaches the API (e.g. empty intent ID). Wraps a sentinel error for errors.Is matching.
var valErr *pay.ValidationError
if errors.As(err, &valErr) {
log.Printf("Invalid input: %s", valErr.Message)
}
UnexpectedError
Wraps unexpected internal errors (JSON marshal failure, request creation, etc.).
var unexpErr *pay.UnexpectedError
if errors.As(err, &unexpErr) {
log.Printf("Unexpected: %v", unexpErr.Err)
}
Sentinel Errors
Use errors.Is (Go) or error type checking to match specific validation failures.
Example (Go)
if errors.Is(err, pay.ErrEmptyIntentID) {
// intent ID was empty
}
HTTP Status Codes
Rate Limiting
The API allows approximately 60 requests per IP per minute. On HTTP 429, implement exponential backoff:
var reqErr *pay.RequestError
if errors.As(err, &reqErr) && reqErr.StatusCode == 429 {
time.Sleep(backoff)
// retry
}