- All Implemented Interfaces:
Serializable,Comparable<HttpStatusFamily>,Constable
HTTP status code classification enum based on RFC 7231 status code families.
This enum provides a type-safe way to classify HTTP status codes into their standard families as defined by RFC 7231. It includes utility methods for checking status code categories and determining appropriate response handling strategies.
Design Principles
- RFC Compliance - Follows RFC 7231 HTTP status code definitions
- Type Safety - Enum-based classification prevents invalid categories
- Utility Methods - Convenient static methods for common checks
- Range Validation - Validates status codes against standard ranges
Status Code Families
- 1xx Informational - Request received, continuing process (100-199)
- 2xx Success - Action successfully received, understood, and accepted (200-299)
- 3xx Redirection - Further action must be taken to complete request (300-399)
- 4xx Client Error - Request contains bad syntax or cannot be fulfilled (400-499)
- 5xx Server Error - Server failed to fulfill apparently valid request (500-599)
- Unknown - Status codes outside standard ranges or error conditions
Usage Examples
// Classify status codes
HttpStatusFamily family = HttpStatusFamily.fromStatusCode(200);
assert family == HttpStatusFamily.SUCCESS;
// Check for success
if (HttpStatusFamily.isSuccess(response.statusCode())) {
// Handle successful response
}
// Check for errors
if (HttpStatusFamily.isClientError(response.statusCode())) {
// Handle client error (4xx)
} else if (HttpStatusFamily.isServerError(response.statusCode())) {
// Handle server error (5xx)
}
// Validate status code range
if (HttpStatusFamily.isValid(statusCode)) {
// Process valid HTTP status code
}
// Family-specific checks
HttpStatusFamily family = HttpStatusFamily.REDIRECTION;
if (family.contains(302)) {
// Handle redirection logic
}
Common Status Codes by Family
- 2xx Success: 200 OK, 201 Created, 204 No Content
- 3xx Redirection: 301 Moved Permanently, 302 Found, 304 Not Modified
- 4xx Client Error: 400 Bad Request, 401 Unauthorized, 404 Not Found
- 5xx Server Error: 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescription4xx: Client Error - The request contains bad syntax or cannot be fulfilled.1xx: Informational - Request received, a continuing process.3xx: Redirection - Further action needs to be taken to complete the request.5xx: Server Error - The server failed to fulfill an apparently valid request.2xx: Success - The action was successfully received, understood, and accepted.Unknown - Used for status codes outside the standard ranges or for error conditions. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(int statusCode) Checks if the given status code belongs to this family.static HttpStatusFamilyfromStatusCode(int statusCode) Gets the HTTP status code family for the given status code.static booleanisClientError(int statusCode) Checks if the given status code indicates a client error (4xx).static booleanisInformational(int statusCode) Checks if the given status code indicates an informational response (1xx).static booleanisRedirection(int statusCode) Checks if the given status code indicates a redirection (3xx).static booleanisServerError(int statusCode) Checks if the given status code indicates a server error (5xx).static booleanisSuccess(int statusCode) Checks if the given status code indicates a successful response (2xx).static booleanisValid(int statusCode) Checks if the given status code is a valid HTTP status code (100-599).toString()static HttpStatusFamilyReturns the enum constant of this class with the specified name.static HttpStatusFamily[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
INFORMATIONAL
1xx: Informational - Request received, a continuing process. -
SUCCESS
2xx: Success - The action was successfully received, understood, and accepted. -
REDIRECTION
3xx: Redirection - Further action needs to be taken to complete the request. -
CLIENT_ERROR
4xx: Client Error - The request contains bad syntax or cannot be fulfilled. -
SERVER_ERROR
5xx: Server Error - The server failed to fulfill an apparently valid request. -
UNKNOWN
Unknown - Used for status codes outside the standard ranges or for error conditions.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
contains
Checks if the given status code belongs to this family.- Parameters:
statusCode- the HTTP status code to check- Returns:
- true if the status code belongs to this family, false otherwise
-
fromStatusCode
Gets the HTTP status code family for the given status code.- Parameters:
statusCode- the HTTP status code- Returns:
- the corresponding HttpStatusFamily family
-
isSuccess
Checks if the given status code indicates a successful response (2xx).- Parameters:
statusCode- the HTTP status code to check- Returns:
- true if the status code indicates success, false otherwise
-
isClientError
Checks if the given status code indicates a client error (4xx).- Parameters:
statusCode- the HTTP status code to check- Returns:
- true if the status code indicates a client error, false otherwise
-
isServerError
Checks if the given status code indicates a server error (5xx).- Parameters:
statusCode- the HTTP status code to check- Returns:
- true if the status code indicates a server error, false otherwise
-
isRedirection
Checks if the given status code indicates a redirection (3xx).- Parameters:
statusCode- the HTTP status code to check- Returns:
- true if the status code indicates a redirection, false otherwise
-
isInformational
Checks if the given status code indicates an informational response (1xx).- Parameters:
statusCode- the HTTP status code to check- Returns:
- true if the status code indicates an informational response, false otherwise
-
isValid
Checks if the given status code is a valid HTTP status code (100-599).- Parameters:
statusCode- the HTTP status code to check- Returns:
- true if the status code is valid, false otherwise
-
toString
- Overrides:
toStringin classEnum<HttpStatusFamily>
-