# SPDX-License-Identifier: Apache-2.0## The OpenSearch Contributors require contributions made to# this file be licensed under the Apache-2.0 license or a# compatible open source license.## Modifications Copyright OpenSearch Contributors. See# GitHub history for details.## Licensed to Elasticsearch B.V. under one or more contributor# license agreements. See the NOTICE file distributed with# this work for additional information regarding copyright# ownership. Elasticsearch B.V. licenses this file to you 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.fromtypingimportAny,Dict,Type,Union__all__=["ImproperlyConfigured","OpenSearchException","SerializationError","TransportError","NotFoundError","ConflictError","RequestError","ConnectionError","SSLError","ConnectionTimeout","AuthenticationException","AuthorizationException","OpenSearchDslException","UnknownDslObject","ValidationException","IllegalOperation","OpenSearchWarning","OpenSearchDeprecationWarning",]
[docs]classImproperlyConfigured(Exception):""" Exception raised when the config passed to the client is inconsistent or invalid. """
[docs]classOpenSearchException(Exception):""" Base class for all exceptions raised by this package's operations (doesn't apply to :class:`~opensearchpy.ImproperlyConfigured`). """
[docs]classSerializationError(OpenSearchException):""" Data passed in failed to serialize properly in the ``Serializer`` being used. """
[docs]classTransportError(OpenSearchException):""" Exception raised when OpenSearch returns a non-OK (>=400) HTTP status code. Or when an actual connection error happens; in that case the ``status_code`` will be set to ``'N/A'``. """@propertydefstatus_code(self)->Union[str,int]:""" The HTTP status code of the response that precipitated the error or ``'N/A'`` if not applicable. """returnself.args[0]# type: ignore@propertydeferror(self)->str:"""A string error message."""returnself.args[1]# type: ignore@propertydefinfo(self)->Union[Dict[str,Any],Exception,Any]:""" Dict of returned error info from OpenSearch, where available, underlying exception when not. """returnself.args[2]
[docs]classConnectionError(TransportError):""" Error raised when there was an exception while talking to OpenSearch. Original exception from the underlying :class:`~opensearchpy.Connection` implementation is available as ``.info``. """
[docs]classOpenSearchWarning(Warning):"""Warning that is raised when a deprecated option or incorrect usage is flagged via the 'Warning' HTTP header. """
# Alias of 'OpenSearchWarning' for backwards compatibility.# Additional functionality was added to the 'Warning' HTTP header# not related to deprecations.OpenSearchDeprecationWarning=OpenSearchWarning# more generic mappings from status_code to python exceptionsHTTP_EXCEPTIONS:Dict[int,Type[OpenSearchException]]={400:RequestError,401:AuthenticationException,403:AuthorizationException,404:NotFoundError,409:ConflictError,}