Skip to content

Commit

Permalink
Update with latest OpenAPI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
moneykitt committed Dec 7, 2023
1 parent 0b284b7 commit 587dc35
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 25 deletions.
2 changes: 1 addition & 1 deletion moneykit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion moneykit/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion moneykit/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
78 changes: 57 additions & 21 deletions moneykit/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -101,53 +103,87 @@ 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"""
error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason)
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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "moneykit"
version = "0.1.2"
version = "0.1.3"
description = "MoneyKit API"
authors = ["OpenAPI Generator Community <[email protected]>"]
license = "NoLicense"
Expand Down

0 comments on commit 587dc35

Please sign in to comment.