3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 class CMHTTPErrors(object):
17 # response for a successful GET, PUT, PATCH, DELETE,
18 # can also be used for POST that does not result in creation.
20 # response to a POST which results in creation.
22 # response to a successfull request that won't be returning any body like a DELETE request
24 # used when http caching headers are in play
25 HTTP_NOT_MODIFIED = 304
26 # the request is malformed such as if the body does not parse
27 HTTP_BAD_REQUEST = 400
28 # when no or invalid authentication details are provided.
29 # also useful to trigger an auth popup API is used from a browser
30 HTTP_UNAUTHORIZED_OPERATION = 401
31 # when authentication succeeded but authenticated user doesn't have access to the resource
33 # when a non-existent resource is requested
35 # when an http method is being requested that isn't allowed for the authenticated user
36 HTTP_METHOD_NOT_ALLOWED = 405
37 # indicates the resource at this point is no longer available
39 # if incorrect content type was provided as part of the request
40 HTTP_UNSUPPORTED_MEDIA_TYPE = 415
41 # used for validation errors
42 HTTP_UNPROCESSABLE_ENTITY = 422
43 # when request is rejected due to rate limiting
44 HTTP_TOO_MANY_REQUESTS = 429
46 HTTP_INTERNAL_ERROR = 500
50 return '%d OK' % CMHTTPErrors.HTTP_OK
53 def get_object_created_successfully_status():
54 return '%d Created' % CMHTTPErrors.HTTP_CREATED
57 def get_request_not_ok_status():
58 return '%d Bad request' % CMHTTPErrors.HTTP_BAD_REQUEST
61 def get_resource_not_found_status():
62 return '%d Not found' % CMHTTPErrors.HTTP_NOT_FOUND
65 def get_unsupported_content_type_status():
66 return '%d Unsupported content type' % CMHTTPErrors.HTTP_UNSUPPORTED_MEDIA_TYPE
69 def get_validation_error_status():
70 return '%d Validation error' % CMHTTPErrors.HTTP_UNPROCESSABLE_ENTITY
73 def get_internal_error_status():
74 return '%d Internal error' % CMHTTPErrors.HTTP_INTERNAL_ERROR