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 | """A library containing exception types used by Endpoints.""" |
| 16 | |
| 17 | from __future__ import absolute_import |
| 18 | |
| 19 | from six.moves import http_client |
| 20 | |
| 21 | from . import remote |
| 22 | |
| 23 | |
| 24 | class ServiceException(remote.ApplicationError): |
| 25 | """Base class for request/service exceptions in Endpoints.""" |
| 26 | |
| 27 | def __init__(self, message=None): |
| 28 | super(ServiceException, self).__init__(message, |
| 29 | http_client.responses[self.http_status]) |
| 30 | |
| 31 | |
| 32 | class BadRequestException(ServiceException): |
| 33 | """Bad request exception that is mapped to a 400 response.""" |
| 34 | http_status = http_client.BAD_REQUEST |
| 35 | |
| 36 | |
| 37 | class UnauthorizedException(ServiceException): |
| 38 | """Unauthorized exception that is mapped to a 401 response.""" |
| 39 | http_status = http_client.UNAUTHORIZED |
| 40 | |
| 41 | |
| 42 | class ForbiddenException(ServiceException): |
| 43 | """Forbidden exception that is mapped to a 403 response.""" |
| 44 | http_status = http_client.FORBIDDEN |
| 45 | |
| 46 | |
| 47 | class NotFoundException(ServiceException): |
| 48 | """Not found exception that is mapped to a 404 response.""" |
| 49 | http_status = http_client.NOT_FOUND |
| 50 | |
| 51 | |
| 52 | class ConflictException(ServiceException): |
| 53 | """Conflict exception that is mapped to a 409 response.""" |
| 54 | http_status = http_client.CONFLICT |
| 55 | |
| 56 | |
| 57 | class GoneException(ServiceException): |
| 58 | """Resource Gone exception that is mapped to a 410 response.""" |
| 59 | http_status = http_client.GONE |
| 60 | |
| 61 | |
| 62 | class PreconditionFailedException(ServiceException): |
| 63 | """Precondition Failed exception that is mapped to a 412 response.""" |
| 64 | http_status = http_client.PRECONDITION_FAILED |
| 65 | |
| 66 | |
| 67 | class RequestEntityTooLargeException(ServiceException): |
| 68 | """Request entity too large exception that is mapped to a 413 response.""" |
| 69 | http_status = http_client.REQUEST_ENTITY_TOO_LARGE |
| 70 | |
| 71 | |
| 72 | class InternalServerErrorException(ServiceException): |
| 73 | """Internal server exception that is mapped to a 500 response.""" |
| 74 | http_status = http_client.INTERNAL_SERVER_ERROR |
| 75 | |
| 76 | |
| 77 | class ApiConfigurationError(Exception): |
| 78 | """Exception thrown if there's an error in the configuration/annotations.""" |
| 79 | |
| 80 | |
| 81 | class InvalidNamespaceException(Exception): |
| 82 | """Exception thrown if there's an invalid namespace declaration.""" |
| 83 | |
| 84 | |
| 85 | class InvalidLimitDefinitionException(Exception): |
| 86 | """Exception thrown if there's an invalid rate limit definition.""" |
| 87 | |
| 88 | |
| 89 | class InvalidApiNameException(Exception): |
| 90 | """Exception thrown if the api name does not match the required character set.""" |
| 91 | |
| 92 | |
| 93 | class ToolError(Exception): |
| 94 | """Exception thrown if there's a general error in the endpointscfg.py tool.""" |