diff --git a/Sources/OllamaKit/OllamaKit+Chat.swift b/Sources/OllamaKit/OllamaKit+Chat.swift index a728cda..e914c45 100644 --- a/Sources/OllamaKit/OllamaKit+Chat.swift +++ b/Sources/OllamaKit/OllamaKit+Chat.swift @@ -42,8 +42,12 @@ extension OllamaKit { case .failure(let error): subject.send(completion: .failure(error)) } - case .complete(_): - subject.send(completion: .finished) + case .complete(let completion): + if completion.error != nil { + subject.send(completion: .failure(completion.error!)) + } else { + subject.send(completion: .finished) + } } } diff --git a/Sources/OllamaKit/OllamaKit+Generate.swift b/Sources/OllamaKit/OllamaKit+Generate.swift index 778d84d..44bbe78 100644 --- a/Sources/OllamaKit/OllamaKit+Generate.swift +++ b/Sources/OllamaKit/OllamaKit+Generate.swift @@ -42,8 +42,12 @@ extension OllamaKit { case .failure(let error): subject.send(completion: .failure(error)) } - case .complete(_): - subject.send(completion: .finished) + case .complete(let completion): + if completion.error != nil { + subject.send(completion: .failure(completion.error!)) + } else { + subject.send(completion: .finished) + } } }