blob: 66fbe86230e49b6bc5deffc4175fe51879103fc0 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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
17from __future__ import absolute_import
18
19from six.moves import http_client
20
21from . import remote
22
23
24class 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
32class BadRequestException(ServiceException):
33 """Bad request exception that is mapped to a 400 response."""
34 http_status = http_client.BAD_REQUEST
35
36
37class UnauthorizedException(ServiceException):
38 """Unauthorized exception that is mapped to a 401 response."""
39 http_status = http_client.UNAUTHORIZED
40
41
42class ForbiddenException(ServiceException):
43 """Forbidden exception that is mapped to a 403 response."""
44 http_status = http_client.FORBIDDEN
45
46
47class NotFoundException(ServiceException):
48 """Not found exception that is mapped to a 404 response."""
49 http_status = http_client.NOT_FOUND
50
51
52class ConflictException(ServiceException):
53 """Conflict exception that is mapped to a 409 response."""
54 http_status = http_client.CONFLICT
55
56
57class GoneException(ServiceException):
58 """Resource Gone exception that is mapped to a 410 response."""
59 http_status = http_client.GONE
60
61
62class PreconditionFailedException(ServiceException):
63 """Precondition Failed exception that is mapped to a 412 response."""
64 http_status = http_client.PRECONDITION_FAILED
65
66
67class 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
72class InternalServerErrorException(ServiceException):
73 """Internal server exception that is mapped to a 500 response."""
74 http_status = http_client.INTERNAL_SERVER_ERROR
75
76
77class ApiConfigurationError(Exception):
78 """Exception thrown if there's an error in the configuration/annotations."""
79
80
81class InvalidNamespaceException(Exception):
82 """Exception thrown if there's an invalid namespace declaration."""
83
84
85class InvalidLimitDefinitionException(Exception):
86 """Exception thrown if there's an invalid rate limit definition."""
87
88
89class InvalidApiNameException(Exception):
90 """Exception thrown if the api name does not match the required character set."""
91
92
93class ToolError(Exception):
94 """Exception thrown if there's a general error in the endpointscfg.py tool."""