Skip to main content
Version: 1.7

Errors

Comprehensive sentinel errors for connection, client, room, and limit error handling.

import "github.com/KARTIKrocks/wshub"
  • Sentinel errors for all error categories
  • Compatible with errors.Is for matching
  • Clear error categories: connection, client, room, limits, auth

Exact signatures live on pkg.go.dev.

Connection Errors

ErrorDescription
ErrConnectionClosedConnection is already closed
ErrInvalidMessageInvalid message received
ErrSendBufferFullClient's send buffer is full (returned by SendMessage)

Hub State Errors

ErrorDescription
ErrHubDrainingUpgradeConnection called while the hub is draining (HTTP 503)
ErrHubStoppedUpgradeConnection called after the hub has been shut down (HTTP 503)
ErrHubNotStartedUpgradeConnection called before Run() has been started (HTTP 503)

Client Errors

ErrorDescription
ErrClientNotFoundClient with the given ID not found

Room Errors

ErrorDescription
ErrEmptyRoomNameRoom name cannot be empty
ErrRoomNotFoundRoom does not exist
ErrAlreadyInRoomClient is already in the room
ErrNotInRoomClient is not in the room
ErrRoomFullRoom has reached max capacity

Limit Errors

ErrorDescription
ErrMaxConnectionsReachedHub has reached maximum connections
ErrMaxUserConnectionsReachedUser has reached max connections per user
ErrMaxRoomsReachedClient has reached max rooms per client
ErrRateLimitExceededClient exceeded the message rate limit
ErrAuthenticationFailedAuthentication failed
ErrUnauthorizedClient is not authorized

Matching Errors

// Check errors with errors.Is
if errors.Is(err, wshub.ErrConnectionClosed) {
log.Println("Connection already closed")
}

if errors.Is(err, wshub.ErrSendBufferFull) {
log.Println("Client send buffer full, message dropped")
}

if errors.Is(err, wshub.ErrRateLimitExceeded) {
log.Println("Client sending too fast")
}

if errors.Is(err, wshub.ErrRoomFull) {
client.SendText("Room is full, try again later")
}

if errors.Is(err, wshub.ErrMaxConnectionsReached) {
log.Println("Server at capacity")
}