Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joemichels opened this issue Aug 13, 2019 · 0 comments
Open

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

joemichels opened this issue Aug 13, 2019 · 0 comments

Comments

@joemichels
Copy link

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")
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant