Swift / Error handling
Swift: handle one Vastu request from setup to result
Use the in-repo Vastu client with configuration, authentication, balance, rate-limit and generic error handling.
These examples use the local VedikaSDK package at sdks/swift in the Vedika repository. The current Swift client covers Vastu. The package requires Swift 5.9, iOS 15 or macOS 12.
Put setup and the request in one boundary
This function uses the existing vastuReference method for the eight-direction reference table. It accepts a key from the caller and never prints it. Defining the function is safe; invoking it with a valid configuration sends a real API request.
import VedikaSDK
func completeReferenceMessage(
apiKey: String,
baseURL: String
) async -> String {
do {
let client = try VedikaClient(
apiKey: apiKey,
baseURL: baseURL
)
_ = try await client.vastu.vastuReference(
"reference/directions/8"
)
return "Response received. Validate the reference data before use."
} catch is VedikaConfigurationError {
return "Review the configured API origin."
} catch is VedikaAuthError {
return "Review the API key configuration."
} catch is VedikaInsufficientCredits {
return "Review the wallet balance."
} catch let limit as VedikaRateLimitError {
if let seconds = limit.retryAfterSeconds, seconds >= 0 {
return "Rate limit reached. Wait at least \(seconds) seconds."
}
return "Rate limit reached. No valid wait time was supplied."
} catch is VedikaServerError {
return "The service returned an error. Review the outcome."
} catch let failure as VedikaApiError {
if failure.statusCode == 403 {
return "Review access for this request."
}
return "The API request failed. Review the request outcome."
} catch {
return "The request could not complete."
}
}
Supply configuration outside the snippet
Obtain the key through your app’s approved credential flow. Do not hard-code it into this guide, source control, logs, or a shared screenshot. Client construction checks the base URL before creating the request session; a rejected origin raises VedikaConfigurationError.
Understand what completion means
The example discards the response to keep error handling in view. Your app must validate and consume the actual reference data. The Swift adapter covers Vastu; this snippet does not imply support for unrelated API domains.
A reference call may be billed. This function adds no retry loop and makes no claim that an error means a charge was reversed. Check the result and account state before another paid call.
Continue with API documentation, current pricing, or support.