2014-11-25 15:59:38 +09:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2016-02-17 11:58:31 +08:00
|
|
|
from magnumclient.common.apiclient import exceptions
|
|
|
|
from magnumclient.common.apiclient.exceptions import * # noqa
|
2014-11-25 15:59:38 +09:00
|
|
|
|
|
|
|
|
|
|
|
# NOTE(akurilin): This alias is left here since v.0.1.3 to support backwards
|
|
|
|
# compatibility.
|
2020-03-28 15:47:38 +01:00
|
|
|
InvalidEndpoint = exceptions.EndpointException
|
|
|
|
CommunicationError = exceptions.ConnectionRefused
|
|
|
|
HTTPBadRequest = exceptions.BadRequest
|
|
|
|
HTTPInternalServerError = exceptions.InternalServerError
|
|
|
|
HTTPNotFound = exceptions.NotFound
|
|
|
|
HTTPServiceUnavailable = exceptions.ServiceUnavailable
|
2014-11-25 15:59:38 +09:00
|
|
|
|
|
|
|
|
2020-03-28 15:47:38 +01:00
|
|
|
class AmbiguousAuthSystem(exceptions.ClientException):
|
2014-11-25 15:59:38 +09:00
|
|
|
"""Could not obtain token and endpoint using provided credentials."""
|
|
|
|
pass
|
|
|
|
|
2017-09-21 15:38:55 +05:30
|
|
|
|
2014-11-25 15:59:38 +09:00
|
|
|
# Alias for backwards compatibility
|
|
|
|
AmbigiousAuthSystem = AmbiguousAuthSystem
|
|
|
|
|
|
|
|
|
2020-03-28 15:47:38 +01:00
|
|
|
class InvalidAttribute(exceptions.ClientException):
|
2014-11-25 15:59:38 +09:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def from_response(response, message=None, traceback=None, method=None,
|
|
|
|
url=None):
|
|
|
|
"""Return an HttpError instance based on response from httplib/requests."""
|
|
|
|
|
|
|
|
error_body = {}
|
|
|
|
if message:
|
|
|
|
error_body['message'] = message
|
|
|
|
if traceback:
|
|
|
|
error_body['details'] = traceback
|
|
|
|
|
|
|
|
if hasattr(response, 'status') and not hasattr(response, 'status_code'):
|
|
|
|
# NOTE(akurilin): These modifications around response object give
|
|
|
|
# ability to get all necessary information in method `from_response`
|
|
|
|
# from common code, which expecting response object from `requests`
|
|
|
|
# library instead of object from `httplib/httplib2` library.
|
|
|
|
response.status_code = response.status
|
|
|
|
response.headers = {
|
|
|
|
'Content-Type': response.getheader('content-type', "")}
|
2015-11-26 16:39:32 -05:00
|
|
|
|
|
|
|
if hasattr(response, 'status_code'):
|
|
|
|
# NOTE(hongbin): This allows SessionClient to handle faultstring.
|
2014-11-25 15:59:38 +09:00
|
|
|
response.json = lambda: {'error': error_body}
|
|
|
|
|
2016-01-08 12:01:14 -05:00
|
|
|
if (response.headers.get('Content-Type', '').startswith('text/') and
|
2015-01-03 21:54:45 -05:00
|
|
|
not hasattr(response, 'text')):
|
|
|
|
# NOTE(clif_h): There seems to be a case in the
|
2016-02-17 11:58:31 +08:00
|
|
|
# common.apiclient.exceptions module where if the
|
2015-01-03 21:54:45 -05:00
|
|
|
# content-type of the response is text/* then it expects
|
|
|
|
# the response to have a 'text' attribute, but that
|
|
|
|
# doesn't always seem to necessarily be the case.
|
|
|
|
# This is to work around that problem.
|
|
|
|
response.text = ''
|
|
|
|
|
2015-11-27 15:28:20 +08:00
|
|
|
return exceptions.from_response(response, method, url)
|