feat(proxy/api/ndJsonStream): handle iterable error
This commit is contained in:
@@ -16,12 +16,16 @@ const { debug, warn } = createLogger('xo:proxy:api')
|
||||
|
||||
const ndJsonStream = asyncIteratorToStream(async function* (responseId, iterable) {
|
||||
yield format.response(responseId, { $responseType: 'ndjson' }) + '\n'
|
||||
for await (const data of iterable) {
|
||||
try {
|
||||
yield JSON.stringify(data) + '\n'
|
||||
} catch (error) {
|
||||
warn('ndJsonStream', { error })
|
||||
try {
|
||||
for await (const data of iterable) {
|
||||
try {
|
||||
yield JSON.stringify(data) + '\n'
|
||||
} catch (error) {
|
||||
warn('ndJsonStream, item error', { error })
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
warn('ndJsonStream, fatal error', { error })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user