2012-11-14 23:58:06 +00:00
|
|
|
# Copyright 2012 Managed I.T.
|
|
|
|
#
|
|
|
|
# Author: Kiall Mac Innes <kiall@managedit.ie>
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
|
|
class Base(Exception):
|
2015-09-01 11:19:01 -06:00
|
|
|
def __init__(self, message=None):
|
|
|
|
if not message:
|
|
|
|
message = self.__class__.__name__
|
2023-11-17 08:44:57 -08:00
|
|
|
super().__init__(message)
|
2012-11-14 23:58:06 +00:00
|
|
|
|
|
|
|
|
2014-11-13 09:56:24 +01:00
|
|
|
class UnsupportedVersion(Base):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2012-11-14 23:58:06 +00:00
|
|
|
class ResourceNotFound(Base):
|
|
|
|
pass
|
2012-11-19 23:08:35 +00:00
|
|
|
|
|
|
|
|
2014-11-13 09:56:24 +01:00
|
|
|
class NoUniqueMatch(Base):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2012-11-19 23:08:35 +00:00
|
|
|
class RemoteError(Base):
|
2013-06-09 15:06:11 +01:00
|
|
|
def __init__(self, message=None, code=None, type=None, errors=None,
|
2017-09-01 10:45:10 +00:00
|
|
|
request_id=None, **ignore):
|
2015-08-21 04:00:10 +00:00
|
|
|
err_message = self._get_error_message(message, type, errors)
|
|
|
|
self.message = err_message
|
2013-03-26 17:16:07 +00:00
|
|
|
self.code = code
|
|
|
|
self.type = type
|
|
|
|
self.errors = errors
|
2013-06-09 15:06:11 +01:00
|
|
|
self.request_id = request_id
|
2012-11-19 23:08:35 +00:00
|
|
|
|
2023-11-17 08:44:57 -08:00
|
|
|
super().__init__(err_message)
|
2015-08-21 04:00:10 +00:00
|
|
|
|
|
|
|
def _get_error_message(self, _message, _type, _errors):
|
|
|
|
# Try to get a useful error msg if 'message' has nothing
|
|
|
|
if not _message:
|
|
|
|
if _errors and 'errors' in _errors:
|
|
|
|
err_msg = list()
|
|
|
|
for err in _errors['errors']:
|
|
|
|
if 'message' in err:
|
|
|
|
err_msg.append(err['message'])
|
|
|
|
_message = '. '.join(err_msg)
|
|
|
|
elif _type:
|
|
|
|
_message = str(_type)
|
|
|
|
return _message
|
|
|
|
|
2012-11-19 23:08:35 +00:00
|
|
|
|
|
|
|
class Unknown(RemoteError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2012-12-11 06:24:48 -08:00
|
|
|
class BadRequest(RemoteError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2012-11-19 23:08:35 +00:00
|
|
|
class Forbidden(RemoteError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Conflict(RemoteError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class NotFound(RemoteError):
|
|
|
|
pass
|
2017-01-31 19:00:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OverQuota(RemoteError):
|
|
|
|
pass
|