Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: third_party/google-endpoints/endpoints/generated_error_info.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 Google Inc. All Rights Reserved.
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 """Automatically generated mapping of error codes."""
16
17 # pylint: disable=g-bad-name
18
19 import collections
20
21
22 _ErrorInfo = collections.namedtuple(
23 '_ErrorInfo', ['http_status', 'rpc_status', 'reason', 'domain'])
24
25 _UNSUPPORTED_ERROR = _ErrorInfo(404,
26 404,
27 'unsupportedProtocol',
28 'global')
29 _BACKEND_ERROR = _ErrorInfo(503,
30 -32099,
31 'backendError',
32 'global')
33 _ERROR_MAP = {
34 400: _ErrorInfo(400, 400, 'badRequest', 'global'),
35 401: _ErrorInfo(401, 401, 'required', 'global'),
36 402: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
37 403: _ErrorInfo(403, 403, 'forbidden', 'global'),
38 404: _ErrorInfo(404, 404, 'notFound', 'global'),
39 405: _ErrorInfo(501, 501, 'unsupportedMethod', 'global'),
40 406: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
41 407: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
42 408: _ErrorInfo(503, -32099, 'backendError', 'global'),
43 409: _ErrorInfo(409, 409, 'conflict', 'global'),
44 410: _ErrorInfo(410, 410, 'deleted', 'global'),
45 411: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
46 412: _ErrorInfo(412, 412, 'conditionNotMet', 'global'),
47 413: _ErrorInfo(413, 413, 'uploadTooLarge', 'global'),
48 414: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
49 415: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
50 416: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
51 417: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'),
52 }
53
54
55 def get_error_info(lily_status):
56 """Get info that would be returned by the server for this HTTP status.
57
58 Args:
59 lily_status: An integer containing the HTTP status returned by the SPI.
60
61 Returns:
62 An _ErrorInfo object containing information that would be returned by the
63 live server for the provided lily_status.
64 """
65 if lily_status >= 500:
66 return _BACKEND_ERROR
67
68 return _ERROR_MAP.get(lily_status, _UNSUPPORTED_ERROR)
OLDNEW
« no previous file with comments | « third_party/google-endpoints/endpoints/errors.py ('k') | third_party/google-endpoints/endpoints/message_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698