public final class TransportErrorCode extends Object implements Serializable
This attempts to match up corresponding HTTP error codes with WebSocket close codes, so that user code can generically select a code without worrying about the underlying transport.
While most WebSocket close codes that we typically use do have a corresponding HTTP error code, there are many HTTP error codes that don't have a corresponding WebSocket close code. In these cases, we use the private WebSocket close code range (4xxx), with the HTTP error code as the last three digits. Such WebSocket close codes will be in the range 4400 to 4599.
This class should only be used to represent error codes, status codes like HTTP 200 should not be represented using this class. This is enforced for HTTP codes, since they have a well defined categorisation, codes between 400 and 599 are considered errors. It is however not enforced for WebSockets, since the WebSocket protocol defines no such categorisation of codes, it specifies a number of well known codes from 1000 to 1015, with no particular pattern to their meaning, and the remaining codes are only categorised by whether they are private, reserved for the WebSocket spec, or reserved for applications to specify.
For WebSocket close codes that are not known, or are not in the private range of 4400 to 4599 defined by us, this use class uses the generic HTTP 404 error code.
Modifier and Type | Field and Description |
---|---|
static TransportErrorCode |
BadRequest
A bad request, most often this will be equivalent to unsupported data.
|
static TransportErrorCode |
Forbidden
A particular operation was forbidden.
|
static TransportErrorCode |
GoingAway
Going away, thrown when the service is unavailable or going away.
|
static TransportErrorCode |
InternalServerError
An internal server error, equivalent to Unexpected Condition.
|
static TransportErrorCode |
MethodNotAllowed
The method being used is not allowed.
|
static TransportErrorCode |
NotAcceptable
The server can't generate a response that meets the clients accepted response types.
|
static TransportErrorCode |
NotFound
A resource was not found, equivalent to policy violation.
|
static TransportErrorCode |
PayloadTooLarge
The payload of a message is too large.
|
static TransportErrorCode |
PolicyViolation
A generic error to used to indicate that the end receiving the error message violated the
remote ends policy.
|
static TransportErrorCode |
ProtocolError
A protocol error, or bad request.
|
static TransportErrorCode |
ServiceUnavailable
Service unavailable, thrown when the service is unavailable or going away.
|
static TransportErrorCode |
UnexpectedCondition
A generic error used to indicate that the end sending the error message because it encountered
an unexpected condition.
|
static TransportErrorCode |
UnsupportedData
An application level protocol error, such as when a client or server sent data that can't be
deserialized.
|
static TransportErrorCode |
UnsupportedMediaType
The client or server doesn't know how to deserialize the request or response.
|
Modifier and Type | Method and Description |
---|---|
String |
description()
A description of this close code.
|
boolean |
equals(Object o) |
static TransportErrorCode |
fromHttp(int code)
Get a transport error code from the given HTTP error code.
|
static TransportErrorCode |
fromWebSocket(int code)
Get a transport error code from the given WebSocket close code.
|
int |
hashCode() |
int |
http()
The HTTP status code for this error.
|
String |
toString() |
int |
webSocket()
The WebSocket close code for this error.
|
public static final TransportErrorCode ProtocolError
public static final TransportErrorCode UnsupportedData
public static final TransportErrorCode BadRequest
public static final TransportErrorCode Forbidden
public static final TransportErrorCode PolicyViolation
public static final TransportErrorCode NotFound
public static final TransportErrorCode MethodNotAllowed
public static final TransportErrorCode NotAcceptable
public static final TransportErrorCode PayloadTooLarge
public static final TransportErrorCode UnsupportedMediaType
public static final TransportErrorCode UnexpectedCondition
public static final TransportErrorCode InternalServerError
public static final TransportErrorCode ServiceUnavailable
public static final TransportErrorCode GoingAway
public static TransportErrorCode fromHttp(int code)
code
- The HTTP error code, must be between 400 and 599 inclusive.IllegalArgumentException
- if the HTTP code was not between 400 and 599.public static TransportErrorCode fromWebSocket(int code)
code
- The WebSocket close code, must be between 0 and 65535 inclusive.IllegalArgumentException
- if the code is not an unsigned 2 byte integer.public int http()
public int webSocket()
public String description()
This description will be meaningful for known built in close codes, but for other codes, it
will be "Unknown error code"
.