diff options
Diffstat (limited to 'python_openapi_client/fatcat_openapi_client/exceptions.py')
-rw-r--r-- | python_openapi_client/fatcat_openapi_client/exceptions.py | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/python_openapi_client/fatcat_openapi_client/exceptions.py b/python_openapi_client/fatcat_openapi_client/exceptions.py index 8d26659c..ac152e04 100644 --- a/python_openapi_client/fatcat_openapi_client/exceptions.py +++ b/python_openapi_client/fatcat_openapi_client/exceptions.py @@ -1,19 +1,14 @@ -# coding: utf-8 - """ fatcat Fatcat is a scalable, versioned, API-oriented catalog of bibliographic entities and file metadata. # noqa: E501 - The version of the OpenAPI document: 0.3.1 + The version of the OpenAPI document: 0.5.0 Contact: webservices@archive.org Generated by: https://openapi-generator.tech """ -import six - - class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -65,6 +60,25 @@ class ApiValueError(OpenApiException, ValueError): super(ApiValueError, self).__init__(full_msg) +class ApiAttributeError(OpenApiException, AttributeError): + def __init__(self, msg, path_to_item=None): + """ + Raised when an attribute reference or assignment fails. + + Args: + msg (str): the exception message + + Keyword Args: + path_to_item (None/list) the path to the exception in the + received_data dict + """ + self.path_to_item = path_to_item + full_msg = msg + if path_to_item: + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) + super(ApiAttributeError, self).__init__(full_msg) + + class ApiKeyError(OpenApiException, KeyError): def __init__(self, msg, path_to_item=None): """ @@ -98,7 +112,7 @@ class ApiException(OpenApiException): def __str__(self): """Custom error messages for exception""" - error_message = "({0})\n"\ + error_message = "Status Code: {0}\n"\ "Reason: {1}\n".format(self.status, self.reason) if self.headers: error_message += "HTTP response headers: {0}\n".format( @@ -110,11 +124,35 @@ class ApiException(OpenApiException): return error_message +class NotFoundException(ApiException): + + def __init__(self, status=None, reason=None, http_resp=None): + super(NotFoundException, self).__init__(status, reason, http_resp) + + +class UnauthorizedException(ApiException): + + def __init__(self, status=None, reason=None, http_resp=None): + super(UnauthorizedException, self).__init__(status, reason, http_resp) + + +class ForbiddenException(ApiException): + + def __init__(self, status=None, reason=None, http_resp=None): + super(ForbiddenException, self).__init__(status, reason, http_resp) + + +class ServiceException(ApiException): + + def __init__(self, status=None, reason=None, http_resp=None): + super(ServiceException, self).__init__(status, reason, http_resp) + + def render_path(path_to_item): """Returns a string representation of a path""" result = "" for pth in path_to_item: - if isinstance(pth, six.integer_types): + if isinstance(pth, int): result += "[{0}]".format(pth) else: result += "['{0}']".format(pth) |