feat: stop generating answers

This commit is contained in:
josc146
2023-03-16 11:20:21 +08:00
parent 91d47a2970
commit 0f97840d23
7 changed files with 79 additions and 9 deletions
+5 -1
View File
@@ -3,9 +3,13 @@ import { streamAsyncIterable } from './stream-async-iterable'
export async function fetchSSE(resource, options) {
const { onMessage, onStart, onEnd, onError, ...fetchOptions } = options
const resp = await fetch(resource, fetchOptions)
const resp = await fetch(resource, fetchOptions).catch(async (err) => {
await onError(err)
})
if (!resp) return
if (!resp.ok) {
await onError(resp)
return
}
const parser = createParser((event) => {
if (event.type === 'event') {