forked from loafle/openapi-generator-original
* Subclass Python exceptions (#7321) * Subclass Python exceptions: - UnauthorizedException (401) - ForbiddenException (403) - NotFoundException (404) - ServiceException [500 - 599] Fixes #2151 * add generated sample code * use Python 2 flavor inheritance * regenerate samples * update samples Co-authored-by: Ryan Rishi <ryan@ryanrishi.com> Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
parent
3de537062d
commit
13f1c610d9
@ -118,6 +118,30 @@ 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 = ""
|
||||
|
@ -12,7 +12,7 @@ from urllib.parse import urlencode
|
||||
import certifi
|
||||
import urllib3
|
||||
|
||||
from {{packageName}}.exceptions import ApiException, ApiValueError
|
||||
from {{packageName}}.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -212,6 +212,18 @@ class RESTClientObject(object):
|
||||
logger.debug("response body: %s", r.data)
|
||||
|
||||
if not 200 <= r.status <= 299:
|
||||
if r.status == 401:
|
||||
raise UnauthorizedException(http_resp=r)
|
||||
|
||||
if r.status == 403:
|
||||
raise ForbiddenException(http_resp=r)
|
||||
|
||||
if r.status == 404:
|
||||
raise NotFoundException(http_resp=r)
|
||||
|
||||
if 500 <= r.status <= 599:
|
||||
raise ServiceException(http_resp=r)
|
||||
|
||||
raise ApiException(http_resp=r)
|
||||
|
||||
return r
|
||||
|
@ -126,6 +126,30 @@ 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 = ""
|
||||
|
@ -20,7 +20,7 @@ from urllib.parse import urlencode
|
||||
import certifi
|
||||
import urllib3
|
||||
|
||||
from petstore_api.exceptions import ApiException, ApiValueError
|
||||
from petstore_api.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -220,6 +220,18 @@ class RESTClientObject(object):
|
||||
logger.debug("response body: %s", r.data)
|
||||
|
||||
if not 200 <= r.status <= 299:
|
||||
if r.status == 401:
|
||||
raise UnauthorizedException(http_resp=r)
|
||||
|
||||
if r.status == 403:
|
||||
raise ForbiddenException(http_resp=r)
|
||||
|
||||
if r.status == 404:
|
||||
raise NotFoundException(http_resp=r)
|
||||
|
||||
if 500 <= r.status <= 599:
|
||||
raise ServiceException(http_resp=r)
|
||||
|
||||
raise ApiException(http_resp=r)
|
||||
|
||||
return r
|
||||
|
@ -126,6 +126,30 @@ 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 = ""
|
||||
|
@ -20,7 +20,7 @@ from urllib.parse import urlencode
|
||||
import certifi
|
||||
import urllib3
|
||||
|
||||
from x_auth_id_alias.exceptions import ApiException, ApiValueError
|
||||
from x_auth_id_alias.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -220,6 +220,18 @@ class RESTClientObject(object):
|
||||
logger.debug("response body: %s", r.data)
|
||||
|
||||
if not 200 <= r.status <= 299:
|
||||
if r.status == 401:
|
||||
raise UnauthorizedException(http_resp=r)
|
||||
|
||||
if r.status == 403:
|
||||
raise ForbiddenException(http_resp=r)
|
||||
|
||||
if r.status == 404:
|
||||
raise NotFoundException(http_resp=r)
|
||||
|
||||
if 500 <= r.status <= 599:
|
||||
raise ServiceException(http_resp=r)
|
||||
|
||||
raise ApiException(http_resp=r)
|
||||
|
||||
return r
|
||||
|
@ -126,6 +126,30 @@ 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 = ""
|
||||
|
@ -20,7 +20,7 @@ from urllib.parse import urlencode
|
||||
import certifi
|
||||
import urllib3
|
||||
|
||||
from dynamic_servers.exceptions import ApiException, ApiValueError
|
||||
from dynamic_servers.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -220,6 +220,18 @@ class RESTClientObject(object):
|
||||
logger.debug("response body: %s", r.data)
|
||||
|
||||
if not 200 <= r.status <= 299:
|
||||
if r.status == 401:
|
||||
raise UnauthorizedException(http_resp=r)
|
||||
|
||||
if r.status == 403:
|
||||
raise ForbiddenException(http_resp=r)
|
||||
|
||||
if r.status == 404:
|
||||
raise NotFoundException(http_resp=r)
|
||||
|
||||
if 500 <= r.status <= 599:
|
||||
raise ServiceException(http_resp=r)
|
||||
|
||||
raise ApiException(http_resp=r)
|
||||
|
||||
return r
|
||||
|
@ -126,6 +126,30 @@ 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 = ""
|
||||
|
@ -20,7 +20,7 @@ from urllib.parse import urlencode
|
||||
import certifi
|
||||
import urllib3
|
||||
|
||||
from petstore_api.exceptions import ApiException, ApiValueError
|
||||
from petstore_api.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -220,6 +220,18 @@ class RESTClientObject(object):
|
||||
logger.debug("response body: %s", r.data)
|
||||
|
||||
if not 200 <= r.status <= 299:
|
||||
if r.status == 401:
|
||||
raise UnauthorizedException(http_resp=r)
|
||||
|
||||
if r.status == 403:
|
||||
raise ForbiddenException(http_resp=r)
|
||||
|
||||
if r.status == 404:
|
||||
raise NotFoundException(http_resp=r)
|
||||
|
||||
if 500 <= r.status <= 599:
|
||||
raise ServiceException(http_resp=r)
|
||||
|
||||
raise ApiException(http_resp=r)
|
||||
|
||||
return r
|
||||
|
Loading…
x
Reference in New Issue
Block a user