How to distinguish request errors from Writable errors in undici.stream
#4417
-
With With QuestionIs there a way to distinguish between:
Exampleimport { Writable } from 'node:stream'
import { stream } from 'undici'
async function main() {
try {
await stream('https://www.google.com/', { method: 'GET' }, () => {
return new Writable({
write(_chunk, _enc, cb) {
cb(new Error('Writable failed'))
},
})
})
} catch (err) {
// ❓ Is there a way to tell if this came from the request vs. the Writable?
console.error('Caught error:', err)
}
}
main() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can just create custom errors and verify the error thrown; nonetheless, the |
Beta Was this translation helpful? Give feedback.
You can just create custom errors and verify the error thrown; nonetheless, the
undici.Stream
has been evaluated as possibly deprecation, I'd advice to useundici.Response.body
readable instead to handle the response and pipeline it or send it to another target.