ResponseContentTransformer
public struct ResponseContentTransformer<InputContentType, OutputContentType> : ResponseTransformer
A simplified ResponseTransformer that deals only with the content of the response entity, and does not touch the
surrounding metadata.
If processEntity(_:) throws or returns nil, the output is an error.
If the input entity’s content does not match the InputContentType, the response is an error.
-
Action to take when actual input type at runtime does not match expected input type declared in code.
See moreDeclaration
Swift
public enum InputTypeMismatchAction -
A closure that both processes the content and describes the required input and output types.
The input will be an
Entitywhosecontentis safely cast to the type expected by the closure. If the response content is not castable toInputContentType, then the pipeline skips the closure and replaces the resopnse with aRequestErrordescribing the type mismatch.The closure can throw an error to indicate that parsing failed. If it throws a
RequestError, that error is passed on to the resource as is. Other failures are wrapped in aRequestError.Declaration
Swift
public typealias Processor = (Entity<InputContentType>) throws -> OutputContentType? -
Declaration
Swift
public init( onInputTypeMismatch mismatchAction: InputTypeMismatchAction = .error, transformErrors: Bool = false, processor: @escaping Processor)Parameters
mismatchActionDetermines what happens when the actual content coming down the pipeline doesn’t match
InputContentType. SeeInputTypeMismatchActionfor options. The default is.error.transformErrorsWhen true, apply the transformation to
RequestError.content(if present). When false, only parse success responses. Default is false.processorThe transformation logic.
-
Declaration
Swift
public var debugDescription: String { get }
View on GitHub
ResponseContentTransformer Structure Reference