Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 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 | from __future__ import absolute_import |
| 20 | |
| 21 | import collections |
| 22 | |
| 23 | _ErrorInfo = collections.namedtuple( |
| 24 | '_ErrorInfo', ['http_status', 'rpc_status', 'reason', 'domain']) |
| 25 | |
| 26 | _UNSUPPORTED_ERROR = _ErrorInfo(404, |
| 27 | 404, |
| 28 | 'unsupportedProtocol', |
| 29 | 'global') |
| 30 | _BACKEND_ERROR = _ErrorInfo(503, |
| 31 | -32099, |
| 32 | 'backendError', |
| 33 | 'global') |
| 34 | _ERROR_MAP = { |
| 35 | 400: _ErrorInfo(400, 400, 'badRequest', 'global'), |
| 36 | 401: _ErrorInfo(401, 401, 'required', 'global'), |
| 37 | 402: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 38 | 403: _ErrorInfo(403, 403, 'forbidden', 'global'), |
| 39 | 404: _ErrorInfo(404, 404, 'notFound', 'global'), |
| 40 | 405: _ErrorInfo(501, 501, 'unsupportedMethod', 'global'), |
| 41 | 406: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 42 | 407: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 43 | 408: _ErrorInfo(503, -32099, 'backendError', 'global'), |
| 44 | 409: _ErrorInfo(409, 409, 'conflict', 'global'), |
| 45 | 410: _ErrorInfo(410, 410, 'deleted', 'global'), |
| 46 | 411: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 47 | 412: _ErrorInfo(412, 412, 'conditionNotMet', 'global'), |
| 48 | 413: _ErrorInfo(413, 413, 'uploadTooLarge', 'global'), |
| 49 | 414: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 50 | 415: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 51 | 416: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 52 | 417: _ErrorInfo(404, 404, 'unsupportedProtocol', 'global'), |
| 53 | } |
| 54 | |
| 55 | |
| 56 | def get_error_info(lily_status): |
| 57 | """Get info that would be returned by the server for this HTTP status. |
| 58 | |
| 59 | Args: |
| 60 | lily_status: An integer containing the HTTP status returned by the SPI. |
| 61 | |
| 62 | Returns: |
| 63 | An _ErrorInfo object containing information that would be returned by the |
| 64 | live server for the provided lily_status. |
| 65 | """ |
| 66 | if lily_status >= 500: |
| 67 | return _BACKEND_ERROR |
| 68 | |
| 69 | return _ERROR_MAP.get(lily_status, _UNSUPPORTED_ERROR) |