StellarSDKLog
public final class StellarSDKLog : Sendable
Logging utility for Stellar SDK error messages and debugging.
This class provides static methods for logging Horizon request errors and error responses to the console. It is primarily used for debugging and troubleshooting issues with API requests.
The logger automatically formats error messages with tags for easy identification and includes detailed information about error responses, XDR data, and result codes when available.
Usage
// Log a Horizon request error
StellarSDKLog.printHorizonRequestErrorMessage(tag: "MyClass", horizonRequestError: error)
// Log an error response directly
if let errorResponse = error.errorResponse {
StellarSDKLog.printErrorResponse(tag: "MyClass", errorResponse: errorResponse)
}
Note
All logging is done to standard output using Swift’s print function. Consider implementing custom log handlers if you need to redirect or filter output.-
Prints a detailed Horizon request error message to the console.
This method examines the error type and prints appropriate diagnostic information including error messages, HTTP status codes, and any error response details provided by Horizon.
Error Types Handled
- Request failures (network errors, timeouts)
- HTTP status errors (400, 401, 403, 404, etc.)
- Rate limiting errors
- Server errors (500, 501, etc.)
- Parsing errors
- Stream errors
Example
sdk.accounts.getAccountDetails(accountId: accountId) { response in switch response { case .failure(let error): StellarSDKLog.printHorizonRequestErrorMessage(tag: "AccountService", horizonRequestError: error) case .success(_): // Handle success } }Declaration
Swift
public static func printHorizonRequestErrorMessage(tag: String, horizonRequestError: HorizonRequestError)Parameters
tagA string identifier for the source of the error (e.g., class or method name)
horizonRequestErrorThe Horizon request error to log
-
Prints detailed information about a Horizon error response.
This method formats and prints all available details from a Horizon error response, including the error type, title, HTTP status code, detail message, and additional diagnostic information such as XDR data and result codes.
Information Logged
- Error type (e.g., “transaction_failed”, “bad_request”)
- Error title (human-readable description)
- HTTP status code
- Detailed error message
- Horizon instance identifier (if available)
- Transaction XDR envelope (if available)
- Result XDR (if available)
- Transaction hash (if available)
- Transaction and operation result codes (if available)
Example
if case .badRequest(_, let errorResponse) = horizonError { StellarSDKLog.printErrorResponse(tag: "TransactionService", errorResponse: errorResponse) }Note
This method is typically called automatically byprintHorizonRequestErrorMessagebut can be used independently when you have an ErrorResponse object.Declaration
Swift
public static func printErrorResponse(tag: String, errorResponse: ErrorResponse?)Parameters
tagA string identifier for the source of the error (e.g., class or method name)
errorResponseThe error response object to log, or nil if unavailable
View on GitHub
Install in Dash