Files
go-omni/ws/errors.go

49 lines
1.6 KiB
Go

package ws
import (
"errors"
"fmt"
)
var (
ErrClosed = errors.New("ws: session closed")
ErrNotConnected = errors.New("ws: not connected")
ErrQueueFull = errors.New("ws: queue full")
ErrMessageTooLarge = errors.New("ws: message too large")
ErrUnsupportedTransport = errors.New("ws: transport does not support websocket upgrade")
ErrServerClosed = errors.New("ws: server closed")
ErrInvalidMessage = errors.New("ws: invalid message")
)
// CloseError deliberately excludes the peer-provided reason, which is untrusted
// and may contain credentials. Cause remains available through errors.Unwrap.
type CloseError struct {
Code int
Cause error
}
func (e *CloseError) Error() string { return fmt.Sprintf("ws: connection closed (code %d)", e.Code) }
func (e *CloseError) Unwrap() error { return e.Cause }
// HandshakeError exposes the HTTP status without putting a URL or response body
// in the error text. Inspect Cause explicitly only when it is safe to do so.
type HandshakeError struct {
StatusCode int
Cause error
}
func (e *HandshakeError) Error() string {
return fmt.Sprintf("ws: handshake failed (HTTP %d)", e.StatusCode)
}
func (e *HandshakeError) Unwrap() error { return e.Cause }
// OpError preserves the underlying cause without including its potentially
// sensitive text in logs. Op is a fixed operation name, never a URL or payload.
type OpError struct {
Op string
Cause error
}
func (e *OpError) Error() string { return "ws: " + e.Op + " failed" }
func (e *OpError) Unwrap() error { return e.Cause }