Swift
Errors
Handle Swift HTTP, networking, encoding, and decoding failures
Overview
This guide explains how to handle errors returned by the Insion SDK and inspect response details when troubleshooting failed requests.
Handle errors
The SDK throws InsionError for all client failures. HTTP failures include the status and optional decoded body.
do {
_ = try await client.moderateARecord(request: request)
} catch let error as InsionError {
switch error {
case .httpError(let httpError):
print(httpError.statusCode, httpError.body?.message ?? httpError.localizedDescription)
case .encodingError(let underlying), .networkError(let underlying):
print(underlying)
default:
print(error)
}
}Cancellation and request options
Cancellation propagates through Swift concurrency. Use request options for additional headers and timeout behavior when diagnosing a call.
How is this guide?