KukaiError

public struct KukaiError : CustomStringConvertible, Error

A struct conforming to Error, attempting to handle errors from all sources (RPC, network, OS, other services/components/libraries), without the implementing code having to deal with each layer themselves. Comes with helpers to extract meaning from RPC errors, optionally includes all the network data that caused the error for easier retrieval, and a fallback human readbale description to ensure something useful is always shown to the user.

  • Categories of errors that are possible

    See more

    Declaration

    Swift

    public enum ErrorType : Equatable
  • The error category

    Declaration

    Swift

    public let errorType: ErrorType
  • Declaration

    Swift

    public let knownErrorMessage: String?
  • Optional error subType coming from another source (the OS, URLSession, another library etc)

    Declaration

    Swift

    public let subType: Error?
  • Optional string containing only the relvant portion of an RPC error (e.g instead of “proto.xxxxxxxx.gas_exhausted.operation”, it would contain “gas_exhausted.operation”) to make parsing easier

    Declaration

    Swift

    public let rpcErrorString: String?
  • Optional object containing smart contract failure casues. May contain an Int (error code), a String (semi human readbale error message), and/or a dictionary containing metadata

    Declaration

    Swift

    public let failWith: FailWith?
  • The requested URL that returned the error

    Declaration

    Swift

    public var requestURL: URL?
  • The JSON that was sent as part of the request

    Declaration

    Swift

    public var requestJSON: String?
  • The raw JSON that was returned

    Declaration

    Swift

    public var responseJSON: String?
  • The HTTP status code returned

    Declaration

    Swift

    public var httpStatusCode: Int?

Constructors

  • Create a KukaiError from an RPC string (will not be validated). You can use the string extension .removeLeadingProtocolFromRPCError() to strip the leading poriton of the error

    Declaration

    Swift

    public static func rpcError(rpcErrorString: String, andFailWith: FailWith?) -> KukaiError
  • Create a KukaiError denoting a sytem issue from the OS, by passing in the system Error type

    Declaration

    Swift

    public static func systemError(subType: Error) -> KukaiError
  • Create a KukaiError denoting a network issue, by passing in the HTTP status code

    Declaration

    Swift

    public static func networkError(statusCode: Int, requestURL: URL) -> KukaiError
  • Create a KukaiError denoting an issue from some other component or library, by passing in the error that piece of code returned

    Declaration

    Swift

    public static func internalApplicationError(error: Error) -> KukaiError
  • Create a KukaiError denoting an issue from some other component or library, by passing in the error that piece of code returned

    Declaration

    Swift

    public static func decodingError(error: Error) -> KukaiError
  • Create a KukaiError allowing a client to simply provide the required error message. E.g. In situations where GraphQL returns a malformed object instead of an error, resulting in a decodingError, a client can catch that, supress it, and instead reutrn an error explaining that this record couldn’t be found

    Declaration

    Swift

    public static func knownErrorMessage(_ message: String) -> KukaiError
  • Create an unknown KukaiError

    Declaration

    Swift

    public static func unknown(withString: String? = nil) -> KukaiError

Modifiers

  • For network errors, attach all the necessary network data that may be needed in order to debug the issue, or log to a tool such as sentry

    Declaration

    Swift

    public mutating func addNetworkData(requestURL: URL?, requestJSON: Data?, responseJSON: Data?, httpStatusCode: Int?)

Display

  • Prints the underlying error type with either an RPC string, or an underlying Error object contents

    Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public func checkErrorForKnownCase(_ err: Error) -> String?
  • Declaration

    Swift

    public func messageForNetworkStatusCode(statusCode: Int, url: URL) -> String