Cause

public enum Cause

Underlying causes of errors reported by Siesta. You will find these on the RequestError.cause property. (Note that cause may also contain errors from the underlying network library that do not appear here.)

The primary purpose of these error causes is to aid debugging. Client code rarely needs to work with them, but they can be useful if you want to add special handling for specific errors.

For example, if you’re working with an API that sometimes returns garbled text data that isn’t decodable, and you want to show users a placeholder message instead of an error, then (1) gee, that’s weird, and (2) you can turn that one specific error into a success by adding a transformer:

configure {
  $0.pipeline[.parsing].add(GarbledResponseHandler())
}

...

struct GarbledResponseHandler: ResponseTransformer {
  func process(_ response: Response) -> Response {
    switch response {
      case .success:
        return response

      case .failure(let error):
        if error.cause is RequestError.Cause.InvalidTextEncoding {
          return .success(Entity<Any>(
            content: "Nothingness. Tumbleweeds. The Void.",
            contentType: "text/string"))
        } else {
          return response
        }
    }
  }
}

Request Errors

Network Errors

Response Errors