Skip to main content

SpendOwlError

Errors that can occur within the SpendOwl SDK.
public enum SpendOwlError: LocalizedError, Sendable, Equatable
All SpendOwl operations are crash-proof. Errors are returned through completion handlers or thrown from async methods.

Error Cases

notConfigured

case notConfigured
The SDK has not been configured. Error Code: 1001 Solution: Call SpendOwl.configure(apiKey:) before using other SDK methods.
do {
    let attribution = try await SpendOwl.attribution()
} catch SpendOwlError.notConfigured {
    // Configure the SDK first
    SpendOwl.configure(apiKey: "your-api-key")
}

invalidAPIKey

case invalidAPIKey
The provided API key is invalid. Error Code: 1002 Solution: Check that you’re using the correct API key from your SpendOwl dashboard.

networkError

case networkError(Error)
A network error occurred. Error Code: 2001 Associated Value: The underlying network error. Notes:
  • The SDK automatically retries failed requests with exponential backoff
  • This error is returned after all retry attempts have failed
do {
    let attribution = try await SpendOwl.attribution()
} catch SpendOwlError.networkError(let underlyingError) {
    print("Network failed: \(underlyingError)")
    // Consider retrying later
}

serverError

case serverError(statusCode: Int, message: String?)
The server returned an error response. Error Code: 2002 Associated Values:
  • statusCode: The HTTP status code
  • message: An optional error message from the server
do {
    let attribution = try await SpendOwl.attribution()
} catch SpendOwlError.serverError(let code, let message) {
    print("Server error \(code): \(message ?? "Unknown")")
}

attributionUnavailable

case attributionUnavailable
Attribution is not available on this device. Error Code: 3001 Causes:
  • iOS version below 14.3
  • AdServices framework not available
  • Running in certain simulator configurations
Solution: This is expected on older devices. Handle gracefully.

attributionDenied

case attributionDenied
Attribution access was denied. Error Code: 3002 Causes:
  • User has enabled “Limit Ad Tracking”
  • MDM profile restricts ad tracking
  • Device privacy settings
Solution: This is normal for some users. Continue without attribution data.

encodingError

case encodingError
Failed to encode request data. Error Code: 4001 Notes: This is an internal error that should not occur in normal operation. If it does, please report it.

decodingError

case decodingError(Error)
Failed to decode the server response. Error Code: 4002 Associated Value: The underlying decoding error. Solution: This may indicate an API version mismatch. Update to the latest SDK version.

unknown

case unknown(Error)
An unknown error occurred. Error Code: 9999 Associated Value: The underlying error for debugging.

Properties

errorDescription

public var errorDescription: String? { get }
A localized description of the error, suitable for display.
catch let error as SpendOwlError {
    print(error.errorDescription ?? "Unknown error")
}

errorCode

public var errorCode: Int { get }
A unique error code for programmatic error handling.
Code RangeCategory
1000-1999Configuration errors
2000-2999Network/server errors
3000-3999Attribution errors
4000-4999Data encoding/decoding errors
9000-9999Unknown errors

Error Handling Examples

Comprehensive Handling

do {
    let attribution = try await SpendOwl.attribution()
    handleAttribution(attribution)
} catch SpendOwlError.notConfigured {
    // SDK not configured
    SpendOwl.configure(apiKey: "your-api-key")
    // Retry
} catch SpendOwlError.invalidAPIKey {
    // Wrong API key - log and alert
    logger.error("Invalid SpendOwl API key")
} catch SpendOwlError.networkError {
    // Network issue - will be retried automatically
    // Consider showing offline indicator
} catch SpendOwlError.serverError(let code, _) where code >= 500 {
    // Server issue - temporary, will resolve
} catch SpendOwlError.attributionUnavailable {
    // Device doesn't support attribution
    // Continue without attribution data
} catch SpendOwlError.attributionDenied {
    // User has tracking disabled
    // Continue without attribution data
} catch {
    // Unknown error
    logger.error("Attribution error: \(error)")
}

Simple Handling

For most apps, simple error handling is sufficient:
do {
    let attribution = try await SpendOwl.attribution()
    // Use attribution
} catch {
    // Log and continue without attribution
    print("Attribution unavailable: \(error.localizedDescription)")
}

Completion Handler Pattern

SpendOwl.attribution { result in
    switch result {
    case .success(let attribution):
        // Handle success
        break
    case .failure(let error):
        switch error {
        case .networkError:
            // Retry later
            break
        default:
            // Log error
            break
        }
    }
}