mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
28 lines
595 B
Go
28 lines
595 B
Go
package helper
|
|
|
|
import (
|
|
"strings"
|
|
"github.com/gorilla/websocket"
|
|
"errors"
|
|
"syscall"
|
|
)
|
|
|
|
func IsUnexpectedWebsocketError(err error) bool {
|
|
// nil error is an expected error
|
|
if err == nil {
|
|
return false
|
|
}
|
|
// 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 true
|
|
}
|
|
|
|
return websocket.IsUnexpectedCloseError(err,
|
|
websocket.CloseGoingAway,
|
|
websocket.CloseNoStatusReceived,
|
|
websocket.CloseNormalClosure)
|
|
}
|