From 587dc3511dc792b9d82c50b6a276f39986647a59 Mon Sep 17 00:00:00 2001 From: moneykitt Date: Thu, 7 Dec 2023 15:29:37 +0000 Subject: [PATCH] Update with latest OpenAPI changes --- moneykit/__init__.py | 2 +- moneykit/api_client.py | 2 +- moneykit/configuration.py | 2 +- moneykit/exceptions.py | 78 ++++++++++++++++++++++++++++----------- pyproject.toml | 2 +- 5 files changed, 61 insertions(+), 25 deletions(-) diff --git a/moneykit/__init__.py b/moneykit/__init__.py index b311c7b..46b7184 100644 --- a/moneykit/__init__.py +++ b/moneykit/__init__.py @@ -14,7 +14,7 @@ """ # noqa: E501 -__version__ = "0.1.2" +__version__ = "0.1.3" # import apis into sdk package from moneykit.api.access_token_api import AccessTokenApi diff --git a/moneykit/api_client.py b/moneykit/api_client.py index d10c910..9d16a4c 100644 --- a/moneykit/api_client.py +++ b/moneykit/api_client.py @@ -76,7 +76,7 @@ def __init__( self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = "OpenAPI-Generator/0.1.2/python" + self.user_agent = "OpenAPI-Generator/0.1.3/python" self.client_side_validation = configuration.client_side_validation def __enter__(self): diff --git a/moneykit/configuration.py b/moneykit/configuration.py index 5f9482c..709e839 100644 --- a/moneykit/configuration.py +++ b/moneykit/configuration.py @@ -406,7 +406,7 @@ def to_debug_report(self): "OS: {env}\n" "Python Version: {pyversion}\n" "Version of the API: 0.1.0\n" - "SDK Package Version: 0.1.2".format(env=sys.platform, pyversion=sys.version) + "SDK Package Version: 0.1.3".format(env=sys.platform, pyversion=sys.version) ) def get_host_settings(self): diff --git a/moneykit/exceptions.py b/moneykit/exceptions.py index 8ebd8c8..e7874b6 100644 --- a/moneykit/exceptions.py +++ b/moneykit/exceptions.py @@ -11,6 +11,8 @@ Do not edit the class manually. """ # noqa: E501 +from typing import Any, Optional, Self + class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -101,17 +103,56 @@ def __init__(self, msg, path_to_item=None) -> None: class ApiException(OpenApiException): - def __init__(self, status=None, reason=None, http_resp=None) -> None: + def __init__( + self, + status=None, + reason=None, + http_resp=None, + *, + body: Optional[str] = None, + data: Optional[Any] = None, + ) -> None: + self.status = status + self.reason = reason + self.body = body + self.data = data + self.headers = None + if http_resp: - self.status = http_resp.status - self.reason = http_resp.reason - self.body = http_resp.data.decode("utf-8") + if self.status is None: + self.status = http_resp.status + if self.reason is None: + self.reason = http_resp.reason + if self.body is None: + try: + self.body = http_resp.data.decode("utf-8") + except Exception: + pass self.headers = http_resp.getheaders() - else: - self.status = status - self.reason = reason - self.body = None - self.headers = None + + @classmethod + def from_response( + cls, + *, + http_resp, + body: Optional[str], + data: Optional[Any], + ) -> Self: + if http_resp.status == 400: + raise BadRequestException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 401: + raise UnauthorizedException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 403: + raise ForbiddenException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 404: + raise NotFoundException(http_resp=http_resp, body=body, data=data) + + if 500 <= http_resp.status <= 599: + raise ServiceException(http_resp=http_resp, body=body, data=data) + raise ApiException(http_resp=http_resp, body=body, data=data) def __str__(self): """Custom error messages for exception""" @@ -119,35 +160,30 @@ def __str__(self): if self.headers: error_message += "HTTP response headers: {0}\n".format(self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message class BadRequestException(ApiException): - def __init__(self, status=None, reason=None, http_resp=None) -> None: - super(BadRequestException, self).__init__(status, reason, http_resp) + pass class NotFoundException(ApiException): - def __init__(self, status=None, reason=None, http_resp=None) -> None: - super(NotFoundException, self).__init__(status, reason, http_resp) + pass class UnauthorizedException(ApiException): - def __init__(self, status=None, reason=None, http_resp=None) -> None: - super(UnauthorizedException, self).__init__(status, reason, http_resp) + pass class ForbiddenException(ApiException): - def __init__(self, status=None, reason=None, http_resp=None) -> None: - super(ForbiddenException, self).__init__(status, reason, http_resp) + pass class ServiceException(ApiException): - def __init__(self, status=None, reason=None, http_resp=None) -> None: - super(ServiceException, self).__init__(status, reason, http_resp) + pass def render_path(path_to_item): diff --git a/pyproject.toml b/pyproject.toml index 8e16f41..45d3172 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "moneykit" -version = "0.1.2" +version = "0.1.3" description = "MoneyKit API" authors = ["OpenAPI Generator Community "] license = "NoLicense"