feat: implement sender and receiver policies based on v1 result codes#514
Conversation
ceddbd5 to
4e95dc9
Compare
87ada5b to
ab174e5
Compare
| const protocolError = this.#toProtocolError(error); | ||
| const rejected = this.#pendingRequestService.rejectPendingRequest(messageId, protocolError); | ||
| if (!rejected) return; | ||
| if (shouldEndConnection(protocolError)) connection.end(); |
There was a problem hiding this comment.
So, if this line disappeared. Cant you just remove the flag from the Error? In general, that is also not great in terms of design. Exceptions (or things that throw) are done in a pub-sub design. That means that the emitter should work as broadcast and the observer (subscriber) should know how to handle those accordingly. If you pass a behavior flag, you are making it so the emitter know the behavior of the subscriber beforehand.
There was a problem hiding this comment.
We could maybe check the result codes here and decide whether to close the connection.
There was a problem hiding this comment.
Okay, so the plan is to create a new module that defines the behavior based on V1ProtocolError, in a similar way to ResultCodePolicy.js It would be even better to rename that file to ResultCodesPolicies.js.
In that module, we would have:
- a sender connection handling policy (Success, Rotate, NoRotate)
- a validator connection handling policy (the ResultCodes that should cause us to close the validator connection).
It will have one big benefit - centralizing all policies into a single file.
@leonardotc @jusufsuljic @leonardostsouza I’m going to merge the current PR as is, and then create a followup issue to refactor it in this direction.
PR Description
This PR improves consistency in v1/network error handling and connection policies, while increasing test reliability.
What changed
Outcome
More consistent error/result behavior, cleaner networking code, and more stable test coverage.