mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-21 16:01:22 +02:00
refactor: improve error handling, validation and proper cleanup
This commit is contained in:
@@ -50,6 +50,7 @@ func (n *Node) NodeCommand(ctx context.Context, command string) (io.ReadCloser,
|
||||
// Send command
|
||||
cmd := []byte(command + "\n")
|
||||
if err := handleSend(cmd); err != nil {
|
||||
closeFn()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -70,6 +71,7 @@ func (n *Node) NodeCommand(ctx context.Context, command string) (io.ReadCloser,
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
_ = pw.CloseWithError(ctx.Err())
|
||||
return
|
||||
case msg := <-recv:
|
||||
// skip the header message like
|
||||
@@ -106,7 +108,6 @@ func (n *Node) NodeCommand(ctx context.Context, command string) (io.ReadCloser,
|
||||
case err := <-errs:
|
||||
if err != nil {
|
||||
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
|
||||
_ = pw.Close()
|
||||
return
|
||||
}
|
||||
_ = pw.CloseWithError(err)
|
||||
|
||||
Reference in New Issue
Block a user