ErrorResponse
public class ErrorResponse : Decodable, @unchecked Sendable
Represents an error response from the Horizon API.
When a request fails, Horizon returns an error response with details about what went wrong. Error responses include HTTP status codes, error types, descriptions, and additional debugging information in the extras field.
Common error types:
- 400 Bad Request: Invalid parameters or malformed request
- 404 Not Found: Resource doesn’t exist
- 429 Rate Limit Exceeded: Too many requests
- 500 Internal Server Error: Server-side problem
Example usage:
let response = await sdk.transactions.submitTransaction(transaction: tx)
switch response {
case .success(let result):
print("Success: \(result.hash)")
case .failure(let error):
if case .badRequest(_, let horizonError) = error,
let errorResponse = horizonError {
print("Error: \(errorResponse.title)")
print("Detail: \(errorResponse.detail)")
// Check for transaction-specific errors
if let extras = errorResponse.extras,
let resultCodes = extras.resultCodes {
print("Transaction result: \(resultCodes.transaction ?? "")")
print("Operation results: \(resultCodes.operations ?? [])")
}
}
}
See also:
- Stellar developer docs
- HorizonRequestError for error enum types
-
URL identifier for the error type. Can be visited for more information.
Declaration
Swift
public let type: String -
Short human-readable summary of the error.
Declaration
Swift
public let title: String -
HTTP status code (400, 404, 429, 500, etc.).
Declaration
Swift
public let httpStatusCode: UInt -
Detailed description of the error and potential solutions.
Declaration
Swift
public let detail: String -
Unique request ID for correlating with server logs. Useful for support requests.
Declaration
Swift
public let instance: String? -
Additional error context including transaction result codes and XDR data.
Declaration
Swift
public let extras: ErrorResponseExtras? -
Initializer - creates a new instance by decoding from the given decoder.
Declaration
Swift
public required init(from decoder: Decoder) throwsParameters
decoderThe decoder containing the data
View on GitHub
Install in Dash