Skip to content

Commit

Permalink
Version Bump v2.3.0: #17 Added support for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingserious committed Jun 21, 2017
1 parent 1c71517 commit 45726d7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

## [2.3.0] - 2017-06-20
### Added
- #17 Added support for error handling
- Thanks [Dibya Prakash Das](https://github.com/dibyadas)!

## [2.2.1] - 2016-08-10
### Fixed
- When Content-Type is not application/json, do not JSON encode the request body
Expand Down
64 changes: 32 additions & 32 deletions python_http_client/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
class HTTPError(Exception):
''' Base of all other errors'''
def __init__(self,error):
self.status_code = error.code
self.reason = error.reason
self.body = error.read()
self.headers = error.hdrs
''' Base of all other errors'''
def __init__(self, error):
self.status_code = error.code
self.reason = error.reason
self.body = error.read()
self.headers = error.hdrs

class BadRequestsError(HTTPError):
pass
pass

class UnauthorizedError(HTTPError):
pass
pass

class ForbiddenError(HTTPError):
pass
pass

class NotFoundError(HTTPError):
pass
pass

class MethodNotAllowedError(HTTPError):
pass
pass

class PayloadTooLargeError(HTTPError):
pass
pass

class UnsupportedMediaTypeError(HTTPError):
pass
pass

class TooManyRequestsError(HTTPError):
pass
pass

class InternalServerError(HTTPError):
pass
pass

class ServiceUnavailableError(HTTPError):
pass
pass

class GatewayTimeoutError(HTTPError):
pass
pass

err_dict = { 400 : BadRequestsError,
401 : UnauthorizedError,
403 : ForbiddenError,
404 : NotFoundError,
405 : MethodNotAllowedError,
413 : PayloadTooLargeError,
415 : UnsupportedMediaTypeError,
429 : TooManyRequestsError,
500 : InternalServerError,
503 : ServiceUnavailableError,
504 : GatewayTimeoutError
401 : UnauthorizedError,
403 : ForbiddenError,
404 : NotFoundError,
405 : MethodNotAllowedError,
413 : PayloadTooLargeError,
415 : UnsupportedMediaTypeError,
429 : TooManyRequestsError,
500 : InternalServerError,
503 : ServiceUnavailableError,
504 : GatewayTimeoutError
}

def handle_error(error):
try:
exc = err_dict[error.code](error)
except KeyError as e:
return HTTPError(error)
return exc
try:
exc = err_dict[error.code](error)
except KeyError as e:
return HTTPError(error)
return exc
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def getRequires():
return deps

base_url = 'https://github.com/sendgrid/'
version = '2.2.1'
version = '2.3.0'
setup(
name='python_http_client',
version=version,
Expand Down

0 comments on commit 45726d7

Please sign in to comment.