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