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
}
}
}
}
-
Resource’s URL is nil or syntactically invalid.
See moreDeclaration
Swift
public struct InvalidURL : Error
-
Unable to create a text request with the requested character encoding.
See moreDeclaration
Swift
public struct UnencodableText : Error
-
Unable to create a JSON request using an object that is not JSON-encodable.
Declaration
Swift
public struct InvalidJSONObject : Error
-
Unable to create a URL-encoded request, probably due to unpaired Unicode surrogate chars.
See moreDeclaration
Swift
public struct NotURLEncodable : Error
-
Underlying network request was cancelled before response arrived.
See moreDeclaration
Swift
public struct RequestCancelled : Error
-
Server sent 304 (“not changed”), but we have no local data for the resource.
Declaration
Swift
public struct NoLocalDataFor304 : Error
-
The server sent a text encoding name that the OS does not recognize.
See moreDeclaration
Swift
public struct InvalidTextEncoding : Error
-
The server’s response could not be decoded using the text encoding it specified.
See moreDeclaration
Swift
public struct UndecodableText : Error
-
Siesta’s default JSON parser accepts only dictionaries and arrays, but the server sent a response containing a bare JSON primitive.
See moreDeclaration
Swift
public struct JSONResponseIsNotDictionaryOrArray : Error
-
The server’s response could not be parsed using any known image format.
Declaration
Swift
public struct UnparsableImage : Error
-
A response transformer received entity content of a type it doesn’t know how to process. This error means that the upstream transformations may have succeeded, but did not return a value of the type the next transformer expected.
See moreDeclaration
Swift
public struct WrongInputTypeInTranformerPipeline : Error
-
A
See moreResponseContentTransformer
or a closure passed toService.configureTransformer(...)
returned nil.Declaration
Swift
public struct TransformerReturnedNil : Error