Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions phrasetms_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,52 @@ def __init__(self, status=None, reason=None, http_resp=None):
super(BadRequestException, 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 NotFoundException(ApiException):

def __init__(self, status=None, reason=None, http_resp=None):
super(NotFoundException, self).__init__(status, reason, http_resp)


class UnauthorizedException(ApiException):
class MethodNotAllowedException(ApiException):

def __init__(self, status=None, reason=None, http_resp=None):
super(UnauthorizedException, self).__init__(status, reason, http_resp)
super(MethodNotAllowedException, self).__init__(status, reason, http_resp)


class ForbiddenException(ApiException):
class TimeoutException(ApiException):

def __init__(self, status=None, reason=None, http_resp=None):
super(ForbiddenException, self).__init__(status, reason, http_resp)
super(TimeoutException, self).__init__(status, reason, http_resp)


class GoneException(ApiException):

def __init__(self, status=None, reason=None, http_resp=None):
super(GoneException, self).__init__(status, reason, http_resp)


class UnsupportedMediaTypeException(ApiException):

def __init__(self, status=None, reason=None, http_resp=None):
super(UnsupportedMediaTypeException, self).__init__(status, reason, http_resp)


class TooManyRequestsException(ApiException):

def __init__(self, status=None, reason=None, http_resp=None):
super(TooManyRequestsException, self).__init__(status, reason, http_resp)


class ServiceException(ApiException):
Expand Down
20 changes: 17 additions & 3 deletions phrasetms_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from urllib.parse import urlencode, quote_plus
import urllib3

from phrasetms_client.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError, BadRequestException
from phrasetms_client.exceptions import ApiException, GoneException, MethodNotAllowedException, TimeoutException, TooManyRequestsException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError, BadRequestException, UnsupportedMediaTypeException


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -69,7 +69,6 @@ def __init__(self, configuration, pools_size=4, maxsize=None):
if configuration.tls_server_name:
addition_pool_args['server_hostname'] = configuration.tls_server_name


if configuration.socket_options is not None:
addition_pool_args['socket_options'] = configuration.socket_options

Expand Down Expand Up @@ -220,7 +219,7 @@ def request(self, method, url, query_params=None, headers=None,
if not 200 <= r.status <= 299:
if r.status == 400:
raise BadRequestException(http_resp=r)

if r.status == 401:
raise UnauthorizedException(http_resp=r)

Expand All @@ -230,6 +229,21 @@ def request(self, method, url, query_params=None, headers=None,
if r.status == 404:
raise NotFoundException(http_resp=r)

if r.status == 405:
raise MethodNotAllowedException(http_resp=r)

if r.status == 408:
raise TimeoutException(http_resp=r)

if r.status == 410:
raise GoneException(http_resp=r)

if r.status == 415:
raise UnsupportedMediaTypeException(http_resp=r)

if r.status == 429:
raise TooManyRequestsException(http_resp=r)

if 500 <= r.status <= 599:
raise ServiceException(http_resp=r)

Expand Down