Skip to content

func decodeBody<Body: Codable>(_ type: Body.Type) is in error #44

@joemichels

Description

@joemichels

I believe the function decodeBody has an error, but I'm not sure.
The function:
public func decodeBody<Body: Codable>(_ type: Body.Type) throws -> Body? {
guard case let .data(bodyData, format)? = body else { return nil }
switch format {
case .json: return try JSONDecoder().decode(type, from: bodyData)
default: throw UnsupportedBodyFormatError(format)
}
}

should not be using .data but I think .codable.

The following code shows what I'm trying to do:
if let iapError = error as? IapStatusCode
{
if iapError.rawValue != IapStatusCode.maliformed.rawValue
{
XCTFail("The wrong error type was returned")
}
print("Not a valid receipt Apple Says: (iapError.errString)")
let theErr = RequestError(rawValue: 204, reason: iapError.errString)
let returnError = RequestError(theErr, body: iapError)
HERE:::: I'm calling REquestError with iapError of type IapStatusCode. This works as expected

 	let theIAPStatusCode = returnError.bodyAs(IapStatusCode.self)

HEEr::: theIAPStatusCode returns nil because of the: [guard case let .data(bodyData, format)? = body else { return nil }] I think it should be .codable

if theIAPStatusCode != IapStatusCode.maliformed
{
	XCTFail("Return Error Incorrect")
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions