BreakerError

public struct BreakerError: Error

An Error representing a failure within the CircuitBreaker call.

BreakerError is intended to be extended to describe command context errors.

Usage Example:

extension BreakerError {
  public static let URLEncodingError = BreakerError(reason: "URL Could Not Be Found")
  public static let responseError = BreakerError(reason: "Invalid Response Error")
}

func myContextFunction(invocation: Invocation<(String), Void, String>) {
  guard let url = URL(string: "http://mysever.net/path/\(invocation.commandArgs)") else {
    invocation.notifyFailure(error: BreakerError.URLEncodingError)
  }

  URLSession.shared.dataTask(with: URLRequest(url: url)) { result, res, err in
    guard let result = result else {
      invocation.notifyFailure(error: BreakerError.responseError)
      return
    }

    invocation.notifySuccess()
  }.resume()
}
  • key

    Unique key for a breaker error.

    Declaration

    Swift

    public let key: String
  • String describing the breaker error.

    Declaration

    Swift

    public let reason: String?
  • Initializes a BreakerError instance for a given key and reason.

    Declaration

    Swift

    public init(key: String? = nil, reason: String? = nil)
  • Initializes a BreakerError instance for a given reason.

    Declaration

    Swift

    public init(reason: String? = nil)
  • Command timeout error.

    Declaration

    Swift

    public static let timeout = BreakerError(key: "Timeout", reason: "A timeout occurred.")
  • Circuit is open - error denoting failing fast state.

    Declaration

    Swift

    public static let fastFail = BreakerError(key: "Fast Fail", reason: "An error occurred in an open state. Failing fast.")
  • A textual description of the BreakerError instance containing the reason.

    Declaration

    Swift

    public var description: String
  • Indicates whether two breaker errors are the same.

    Declaration

    Swift

    public static func ==(lhs: BreakerError, rhs: BreakerError) -> Bool