Skip to content

Commit

Permalink
Fix a Codebeat issue with transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
wmcginty committed Sep 24, 2018
1 parent f6e722b commit f85792c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/Hyperspace/Request/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public struct RequestDefaults {

public static func dataTransformer<ResponseType: Decodable, ErrorType: DecodingFailureInitializable>(for decoder: JSONDecoder) -> (Data) -> Result<ResponseType, ErrorType> {
return dataTransformer(for: decoder) {
guard let decodingError = $0 as? DecodingError else { fatalError("JSONDecoder should always throw a DecodingError.") }
return ErrorType(error: decodingError, decoding: ResponseType.self, data: $2)
return error(from: $0, decoding: ResponseType.self, from: $2)
}
}

Expand All @@ -128,10 +127,14 @@ public struct RequestDefaults {
public static func dataTransformer<ContainerType: DecodableContainer, ErrorType: DecodingFailureInitializable>(for decoder: JSONDecoder,
withContainerType containerType: ContainerType.Type) -> (Data) -> Result<ContainerType.ContainedType, ErrorType> {
return dataTransformer(for: decoder, withContainerType: containerType) {
guard let decodingError = $0 as? DecodingError else { fatalError("JSONDecoder should always throw a DecodingError.") }
return ErrorType(error: decodingError, decoding: ContainerType.self, data: $2)
return error(from: $0, decoding: ContainerType.self, from: $2)
}
}

private static func error<ErrorType: DecodingFailureInitializable>(from error: Swift.Error, decoding type: Decodable.Type, from data: Data) -> ErrorType {
guard let decodingError = error as? DecodingError else { fatalError("JSONDecoder should always throw a DecodingError.") }
return ErrorType(error: decodingError, decoding: type, data: data)
}
}

// MARK: - Request Default Implementations
Expand Down

0 comments on commit f85792c

Please sign in to comment.