openai-node
openai-node copied to clipboard
on('error', () => ...) event does not fire on APIUserAbortError
Confirm this is a Node library issue and not an underlying OpenAI API issue
- [X] This is an issue with the Node library
Describe the bug
From the error event documentation:
The event fired when an error is encountered outside of a parse function or an abort.
However, I found that it is not fired on abort. Instead, the way to gracefully handle an abort seems to be with the finalContent method (there may be other ways, I didn't test). I found this out from looking at the tests.
To Reproduce
This test already has the minimal setup to reproduce. Simply add an assertion to expect emittedError to be present after aborting.
Code snippets
No response
OS
macOS
Node version
20.9.0
Library version
4.18.0
Sorry about that. We hope to fix this when we can. In the meantime, you can listen to .on('abort') for this purpose. Does that work well for you?
Out of curiosity, is there a reason you'd like .on('error') to throw on aborts rather than listening to .on('abort') separately, or was it simply because that was what the docs told you to do?
.on('abort') works fine for my use case, I made this issue before trying it out :).