Source code for descarteslabs.exceptions

# Copyright 2018-2024 Descartes Labs.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Exceptions raised by HTTP clients."""


[docs]class ClientError(Exception): """Base class for all client exceptions.""" pass
[docs]class AuthError(ClientError): """Authentication error, improperly supplied credentials.""" pass
[docs]class OauthError(AuthError): """Authentication error, failure from OAuth authentication service.""" pass
[docs]class ConfigError(Exception): """Configuration error during initial configuration of the library.""" pass
[docs]class ServerError(Exception): """Server or service failure.""" status = 500
[docs]class BadRequestError(ClientError): """Client request with incorrect parameters.""" status = 400
[docs]class UnauthorizedError(ClientError): """Client request lacking authentication.""" status = 401
[docs]class ForbiddenError(ClientError): """Client request lacks necessary permissions.""" status = 403
[docs]class NotFoundError(ClientError): """Resource not found.""" status = 404
[docs]class MethodNotAllowedError(ClientError): """Requested nethod not supported by the resource.""" status = 405
[docs]class ProxyAuthenticationRequiredError(ClientError): """Client request needs proxy authentication. Attributes ========== status : int The status code of the error response. proxy_authenticate : Optional[str] A `ProxyAuthenticate <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authenticate>`_ header if found in the response. """ status = 407 def __init__(self, message, proxy_authenticate=None) -> None: super(ProxyAuthenticationRequiredError, self).__init__(message) self.proxy_authenticate = proxy_authenticate
[docs]class ConflictError(ClientError): """Client request conflicts with existing state.""" status = 409
[docs]class GoneError(ClientError): """Client request to a URL which has been permanently removed.""" status = 410
[docs]class ValidationError(BadRequestError): """Client request with invalid parameters.""" status = 422
[docs]class RateLimitError(ClientError): """ Client request exceeds rate limits. The retry_after member will contain any time limit returned in the response. """ status = 429 def __init__(self, message, retry_after=None): """ Construct a new instance. :param str message: The error message. :type retry_after: str or None :param retry_after: An indication of a ``retry-after`` timeout specified by the error response. """ super(RateLimitError, self).__init__(message) self.retry_after = retry_after
[docs]class RetryWithError(ClientError): """Vector service query request timed out.""" status = 449
[docs]class GatewayTimeoutError(ServerError): """Timeout from the gateway after failing to route request to destination service.""" status = 504
[docs]class RequestCancellationError(ClientError): """Client cancelled the request and no status or response was received."""