nats-io/nats-server · error
http.StatusText(status)
Error message
http.StatusText(status)
What it means
The HTTP status line text produced by wsReturnHTTPError() when writing the error body via http.Error(). Not a distinct error condition: it renders the human-readable name (e.g. '403 Forbidden') of the status passed for the failed websocket handshake, accompanying the '%s - websocket handshake error: %s' error.
Source
Thrown at server/websocket.go:1025
}
if snc && cnc {
return true, true
}
}
return true, false
}
}
}
}
return false, false
}
// Send an HTTP error with the given `status` to the given http response writer `w`.
// Return an error created based on the `reason` string.
func wsReturnHTTPError(w http.ResponseWriter, r *http.Request, status int, reason string) error {
err := fmt.Errorf("%s - websocket handshake error: %s", r.RemoteAddr, reason)
w.Header().Set("Sec-Websocket-Version", "13")
http.Error(w, http.StatusText(status), status)
return err
}
// If the server is configured to accept any origin, then this function returns
// `nil` without checking if the Origin is present and valid. This is also
// the case if the request does not have the Origin header.
// Otherwise, this will check that the Origin matches the same origin or
// any origin in the allowed list.
func (w *srvWebsocket) checkOrigin(r *http.Request) error {
w.mu.RLock()
checkSame := w.sameOrigin
listEmpty := len(w.allowedOrigins) == 0
w.mu.RUnlock()
if !checkSame && listEmpty {
return nil
}
origin := r.Header.Get("Origin")
if origin == _EMPTY_ {View on GitHub (pinned to 3a66a489d2)
Solutions
- Inspect the accompanying handshake error and status code to determine why the upgrade was refused
- Fix the client request or server websocket options per the reported reason
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at server/websocket.go:1025 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/3e573824ab4d9ea1.
Report an issue: GitHub.