Skip to content

Commit

Permalink
Fix crash after Task cancellation by removing unneeded error processi…
Browse files Browse the repository at this point in the history
…ng (#45)

- After Task cancellation, this preconditionFailure was triggered: "Tried to use a second iterator on response body stream. Multiple iterators are not supported."
- Also the following: fatalError("NIOThrowingAsyncSequenceProducer allows only a single AsyncIterator to be created")
  • Loading branch information
JSky74 committed May 12, 2023
1 parent 6d9533e commit db5c74c
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions Sources/OpenAIKit/RequestHandler/RequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,7 @@ struct RequestHandler {
}
continuation.finish()
} catch {

let data = try? await response.body.reduce(into: Data()) { $0.append(.init(buffer: $1)) }

if let data = data,
let apiError = try? decoder.decode(APIErrorResponse.self, from: data) {
continuation.finish(throwing: apiError)
} else {
continuation.finish(throwing: error)
}

continuation.finish(throwing: error)
}
}
}
Expand Down

0 comments on commit db5c74c

Please sign in to comment.