nginx_ui/nginx-ui-dev/internal/helper/websocket_error.go
2025-03-04 11:28:12 +00:00

26 lines
609 B
Go

package helper
import (
"errors"
"github.com/gorilla/websocket"
"strings"
"syscall"
)
// IsUnexpectedWebsocketError checks if the error is an unexpected websocket error
func IsUnexpectedWebsocketError(err error) bool {
// ignore: write: broken pipe
if errors.Is(err, syscall.EPIPE) {
return false
}
// client closed error: *net.OpErr
if strings.Contains(err.Error(), "An existing connection was forcibly closed by the remote host") {
return false
}
return websocket.IsUnexpectedCloseError(err,
websocket.CloseGoingAway,
websocket.CloseNoStatusReceived,
websocket.CloseNormalClosure)
}