A noob question about SwiftNIO

First of all, sorry for my bad English.
Suppose I use AsyncHTTPClient in my project, and I have codes like this:

private func HTTPRequest<D: Decodable>(_ request: HTTPClient.Request) -> EventLoopFuture<RespMessage<D>> {
    return httpClient.execute(request: request).flatMapThrowing { response in
        guard response.status == .ok else {
            return // 1.
        guard let buff = response.body else {
            return // 2.
        let respMsg = try JSONDecoder().decode(RespMessage<D>.self, from: buff)
        return respMsg

I just want to know , in the comment 1 and 2 where I want to make the future fail, how to do things like this?

I think you can just throw an error here and it will be "flatMapped" into a failing future.

1 Like
Terms of Service

Privacy Policy

Cookie Policy