forked from folio-org/raml-module-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpStatus.java
More file actions
117 lines (103 loc) · 3.79 KB
/
HttpStatus.java
File metadata and controls
117 lines (103 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package org.folio;
/**
* HTTP status codes of FOLIO's APIs.
*/
public enum HttpStatus {
/**
* 200, the request has succeeded. The information returned with the
* response is dependent on the method used in the request, as follows:
*
* <ul><li>GET - an entity corresponding to the requested resource is sent
* in the response;</li>
* <li>HEAD - the response must only contain the header information and
no Entity-Body;</li>
* <li>POST - an entity describing or containing the result of the action</li>
* </ul>
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.2">RFC 1945 Section 9.2</a>.
*/
HTTP_ACCEPTED(200),
/**
* 201, the request has succeeded. The information returned with the
* response is dependent on the method used in the request, as follows:
*
* <ul><li>GET - an entity corresponding to the requested resource is sent
* in the response;</li>
*
* <li>HEAD - the response must only contain the header information and
* no Entity-Body;</li>
*
* <li>POST - an entity describing or containing the result of the action.</li>
* </ul>
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.2">RFC 1945 Section 9.2</a>.
*/
HTTP_CREATED(201),
/**
* 204, the request was successful but there is no new information to send back.
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.2">RFC 1945 Section 9.2</a>.
* To be returned on successful POST, PUT and DELETE requests.
*/
HTTP_NO_CONTENT(204),
/**
* 400, the request has malformed syntax and was rejected. Do not repeat without modifications.
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.4">RFC 1945 Section 9.4</a>.
*/
HTTP_BAD_REQUEST(400),
/**
* 401, authentication is missing or invalid.
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.4">RFC 1945 Section 9.4</a>.
*/
HTTP_UNAUTHORIZED(401),
/**
* 403, the access is denied because of insufficient privileges.
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.4">RFC 1945 Section 9.4</a>.
*/
HTTP_FORBIDDEN(403),
/**
* 404, nothing has been found matching the request URI.
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.4">RFC 1945 Section 9.4</a>.
*/
HTTP_NOT_FOUND(404),
/**
* 422, the validation of the request failed. The body, the URI parameters or the HTTP
* headers do not comply with the requirements published with the FOLIO API.
*/
HTTP_VALIDATION_ERROR(422),
/**
* 500, internal server error. The server encountered an unexpected condition which prevented it
* from fulfilling the request.
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.5">RFC 1945 Section 9.5</a>.
*/
HTTP_INTERNAL_SERVER_ERROR(500),
/**
* 501, the functionality required to fulfill the request is not supported. This is the
* appropriate response when the server does not recognize the request method and is not
* capable of supporting it for any resource.
* See <a href="https://tools.ietf.org/html/rfc1945#section-9.5">RFC 1945 Section 9.5</a>.
*/
HTTP_NOT_IMPLEMENTED(501);
private final int value;
HttpStatus(int value) {
this.value = value;
}
/**
* @return status code as int value
*/
public int toInt() {
return value;
}
/**
* Convert int to HttpStatus.
*
* @param value int value of the HttpStatus to return
* @return HttpStatus
* @throws IllegalArgumentException if there isn't an HttpStatus for value
*/
public static HttpStatus get(int value) {
for (HttpStatus status : HttpStatus.values()) {
if (status.value == value) {
return status;
}
}
throw new IllegalArgumentException("FOLIO does not specify a name for HTTP status value " + value);
}
}