Skip to content

Commit

Permalink
feat($HTTPStatus): add more HTTP statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed May 9, 2020
1 parent 4bf18e0 commit 4dc81c3
Showing 1 changed file with 143 additions and 12 deletions.
155 changes: 143 additions & 12 deletions common/src/main/java/com/jmsoftware/common/constant/HttpStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,99 @@
* @date 2019-03-23 16:48
* @see <a href="https://www.iana.org/assignments/http-status-codes">HTTP Status Code Registry</a>
* @see <a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes">List of HTTP status codes</a>
**/
*/
@Getter
@ToString
@SuppressWarnings("unused")
public enum HttpStatus implements IUniversalStatus {
// 2xx Success
/*
Value Description Reference
100 Continue [RFC7231, Section 6.2.1]
101 Switching Protocols [RFC7231, Section 6.2.2]
102 Processing [RFC2518]
103 Early Hints [RFC8297]
104-199 Unassigned
200 OK [RFC7231, Section 6.3.1]
201 Created [RFC7231, Section 6.3.2]
202 Accepted [RFC7231, Section 6.3.3]
203 Non-Authoritative Information [RFC7231, Section 6.3.4]
204 No Content [RFC7231, Section 6.3.5]
205 Reset Content [RFC7231, Section 6.3.6]
206 Partial Content [RFC7233, Section 4.1]
207 Multi-Status [RFC4918]
208 Already Reported [RFC5842]
209-225 Unassigned
226 IM Used [RFC3229]
227-299 Unassigned
300 Multiple Choices [RFC7231, Section 6.4.1]
301 Moved Permanently [RFC7231, Section 6.4.2]
302 Found [RFC7231, Section 6.4.3]
303 See Other [RFC7231, Section 6.4.4]
304 Not Modified [RFC7232, Section 4.1]
305 Use Proxy [RFC7231, Section 6.4.5]
306 (Unused) [RFC7231, Section 6.4.6]
307 Temporary Redirect [RFC7231, Section 6.4.7]
308 Permanent Redirect [RFC7538]
309-399 Unassigned
400 Bad Request [RFC7231, Section 6.5.1]
401 Unauthorized [RFC7235, Section 3.1]
402 Payment Required [RFC7231, Section 6.5.2]
403 Forbidden [RFC7231, Section 6.5.3]
404 Not Found [RFC7231, Section 6.5.4]
405 Method Not Allowed [RFC7231, Section 6.5.5]
406 Not Acceptable [RFC7231, Section 6.5.6]
407 Proxy Authentication Required [RFC7235, Section 3.2]
408 Request Timeout [RFC7231, Section 6.5.7]
409 Conflict [RFC7231, Section 6.5.8]
410 Gone [RFC7231, Section 6.5.9]
411 Length Required [RFC7231, Section 6.5.10]
412 Precondition Failed [RFC7232, Section 4.2][RFC8144, Section 3.2]
413 Payload Too Large [RFC7231, Section 6.5.11]
414 URI Too Long [RFC7231, Section 6.5.12]
415 Unsupported Media Type [RFC7231, Section 6.5.13][RFC7694, Section 3]
416 Range Not Satisfiable [RFC7233, Section 4.4]
417 Expectation Failed [RFC7231, Section 6.5.14]
418-420 Unassigned
421 Misdirected Request [RFC7540, Section 9.1.2]
422 Unprocessable Entity [RFC4918]
423 Locked [RFC4918]
424 Failed Dependency [RFC4918]
425 Too Early [RFC8470]
426 Upgrade Required [RFC7231, Section 6.5.15]
427 Unassigned
428 Precondition Required [RFC6585]
429 Too Many Requests [RFC6585]
430 Unassigned
431 Request Header Fields Too Large [RFC6585]
432-450 Unassigned
451 Unavailable For Legal Reasons [RFC7725]
452-499 Unassigned
500 Internal Server Error [RFC7231, Section 6.6.1]
501 Not Implemented [RFC7231, Section 6.6.2]
502 Bad Gateway [RFC7231, Section 6.6.3]
503 Service Unavailable [RFC7231, Section 6.6.4]
504 Gateway Timeout [RFC7231, Section 6.6.5]
505 HTTP Version Not Supported [RFC7231, Section 6.6.6]
506 Variant Also Negotiates [RFC2295]
507 Insufficient Storage [RFC4918]
508 Loop Detected [RFC5842]
509 Unassigned
510 Not Extended [RFC2774]
511 Network Authentication Required [RFC6585]
512-599 Unassigned
*/

// --- 2xx Success ---
/**
* Success
*/
OK(200, "OK. The standard response for successful HTTP requests."),

// --- 4xx Client Error ---
/**
* Bad request
*/
BAD_REQUEST(400, "Bad request. The server cannot or will not process the request due to an apparent client error."),
/**
* Unauthorized
*/
Expand All @@ -42,9 +123,10 @@ public enum HttpStatus implements IUniversalStatus {
*/
METHOD_NOT_ALLOWED(405, "The resource was requested using a method that is not allowed."),
/**
* Bad request
* Not acceptable
*/
BAD_REQUEST(400, "Bad request."),
NOT_ACCEPTABLE(406, "Not Acceptable. The requested resource is capable of generating only content not acceptable " +
"according to the Accept headers sent in the request."),
/**
* Param not matched
*/
Expand Down Expand Up @@ -75,7 +157,27 @@ public enum HttpStatus implements IUniversalStatus {
/**
* Error or failure
*/
ERROR(500, "Error. A generic status for an error in the server itself."),
ERROR(500, "Internal server error. A generic status for an error in the server itself."),
/**
* Not implemented
*/
NOT_IMPLEMENTED(501, "Not implemented. The server either does not recognize the request method, or it lacks the " +
"ability to fulfil the request."),
/**
* Bad gateway
*/
BAD_GATEWAY(502, "Bad gateway. The server was acting as a gateway or proxy and received an invalid response from " +
"the upstream server."),
/**
* Service unavailable
*/
SERVICE_UNAVAILABLE(503, "Service unavailable. The server cannot handle the request (because it is overloaded or " +
"down for maintenance). Generally, this is a temporary state."),
/**
* Gateway timeout
*/
GATEWAY_TIMEOUT(504, "Gateway timeout. The server was acting as a gateway or proxy and did not receive a timely " +
"response from the upstream server."),
/**
* Role not found
*/
Expand Down Expand Up @@ -111,11 +213,23 @@ public enum HttpStatus implements IUniversalStatus {
*/
private final String message;

/**
* Instantiates a new Http status.
*
* @param code the code
* @param message the message
*/
HttpStatus(Integer code, String message) {
this.code = code;
this.message = message;
}

/**
* From code http status.
*
* @param code the code
* @return the http status
*/
public static HttpStatus fromCode(Integer code) {
HttpStatus[] httpStatuses = HttpStatus.values();
for (HttpStatus httpStatus : httpStatuses) {
Expand All @@ -129,6 +243,7 @@ public static HttpStatus fromCode(Integer code) {
/**
* Return the HTTP status series of this status code.
*
* @return the series
* @see HttpStatus.Series
*/
public Series series() {
Expand All @@ -139,7 +254,8 @@ public Series series() {
* Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
* This is a shortcut for checking the value of {@link #series()}.
*
* @see #series()
* @return the boolean
* @see #series() #series()
*/
public boolean is1xxInformational() {
return (series() == Series.INFORMATIONAL);
Expand All @@ -149,7 +265,8 @@ public boolean is1xxInformational() {
* Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
* This is a shortcut for checking the value of {@link #series()}.
*
* @see #series()
* @return the boolean
* @see #series() #series()
*/
public boolean is2xxSuccessful() {
return (series() == Series.SUCCESSFUL);
Expand All @@ -159,7 +276,8 @@ public boolean is2xxSuccessful() {
* Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
* This is a shortcut for checking the value of {@link #series()}.
*
* @see #series()
* @return the boolean
* @see #series() #series()
*/
public boolean is3xxRedirection() {
return (series() == Series.REDIRECTION);
Expand All @@ -169,7 +287,8 @@ public boolean is3xxRedirection() {
* Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
*
* @see #series()
* @return the boolean
* @see #series() #series()
*/
public boolean is4xxClientError() {
return (series() == Series.CLIENT_ERROR);
Expand All @@ -179,7 +298,8 @@ public boolean is4xxClientError() {
* Whether this status code is in the HTTP series {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
*
* @see #series()
* @return the boolean
* @see #series() #series()
*/
public boolean is5xxServerError() {
return (series() == Series.SERVER_ERROR);
Expand All @@ -190,8 +310,9 @@ public boolean is5xxServerError() {
* {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}. This is a shortcut for checking the value of
* {@link #series()}.
*
* @see #is4xxClientError()
* @see #is5xxServerError()
* @return the boolean
* @see #is4xxClientError() #is4xxClientError()
* @see #is5xxServerError() #is5xxServerError()
* @since 5.0
*/
public boolean isError() {
Expand Down Expand Up @@ -224,14 +345,24 @@ public enum Series {
*/
SERVER_ERROR(5);

/**
* The Value.
*/
private final int value;

/**
* Instantiates a new Series.
*
* @param value the value
*/
Series(int value) {
this.value = value;
}

/**
* Return the integer value of this status series. Ranges from 1 to 5.
*
* @return the int
*/
public int value() {
return this.value;
Expand Down

0 comments on commit 4dc81c3

Please sign in to comment.