Initial commit
[ta/config-manager.git] / cmframework / src / cmframework / server / cmhttperrors.py
1 # Copyright 2019 Nokia
2
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15
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.
19     HTTP_OK = 200
20     # response to a POST which results in creation.
21     HTTP_CREATED = 201
22     # response to a successfull request that won't be returning any body like a DELETE request
23     HTTP_NO_CONTENT = 204
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
32     HTTP_FORBIDDEN = 403
33     # when a non-existent resource is requested
34     HTTP_NOT_FOUND = 404
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
38     HTTP_GONE = 410
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
45     # Other errrors
46     HTTP_INTERNAL_ERROR = 500
47
48     @staticmethod
49     def get_ok_status():
50         return '%d OK' % CMHTTPErrors.HTTP_OK
51
52     @staticmethod
53     def get_object_created_successfully_status():
54         return '%d Created' % CMHTTPErrors.HTTP_CREATED
55
56     @staticmethod
57     def get_request_not_ok_status():
58         return '%d Bad request' % CMHTTPErrors.HTTP_BAD_REQUEST
59
60     @staticmethod
61     def get_resource_not_found_status():
62         return '%d Not found' % CMHTTPErrors.HTTP_NOT_FOUND
63
64     @staticmethod
65     def get_unsupported_content_type_status():
66         return '%d Unsupported content type' % CMHTTPErrors.HTTP_UNSUPPORTED_MEDIA_TYPE
67
68     @staticmethod
69     def get_validation_error_status():
70         return '%d Validation error' % CMHTTPErrors.HTTP_UNPROCESSABLE_ENTITY
71
72     @staticmethod
73     def get_internal_error_status():
74         return '%d Internal error' % CMHTTPErrors.HTTP_INTERNAL_ERROR