Skip to content

Commit 45726d7

Browse files
Version Bump v2.3.0: #17 Added support for error handling
1 parent 1c71517 commit 45726d7

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
33

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

6+
## [2.3.0] - 2017-06-20
7+
### Added
8+
- #17 Added support for error handling
9+
- Thanks [Dibya Prakash Das](https://github.com/dibyadas)!
10+
611
## [2.2.1] - 2016-08-10
712
### Fixed
813
- When Content-Type is not application/json, do not JSON encode the request body

python_http_client/exceptions.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
class HTTPError(Exception):
2-
''' Base of all other errors'''
3-
def __init__(self,error):
4-
self.status_code = error.code
5-
self.reason = error.reason
6-
self.body = error.read()
7-
self.headers = error.hdrs
2+
''' Base of all other errors'''
3+
def __init__(self, error):
4+
self.status_code = error.code
5+
self.reason = error.reason
6+
self.body = error.read()
7+
self.headers = error.hdrs
88

99
class BadRequestsError(HTTPError):
10-
pass
10+
pass
1111

1212
class UnauthorizedError(HTTPError):
13-
pass
13+
pass
1414

1515
class ForbiddenError(HTTPError):
16-
pass
16+
pass
1717

1818
class NotFoundError(HTTPError):
19-
pass
19+
pass
2020

2121
class MethodNotAllowedError(HTTPError):
22-
pass
22+
pass
2323

2424
class PayloadTooLargeError(HTTPError):
25-
pass
25+
pass
2626

2727
class UnsupportedMediaTypeError(HTTPError):
28-
pass
28+
pass
2929

3030
class TooManyRequestsError(HTTPError):
31-
pass
31+
pass
3232

3333
class InternalServerError(HTTPError):
34-
pass
34+
pass
3535

3636
class ServiceUnavailableError(HTTPError):
37-
pass
37+
pass
3838

3939
class GatewayTimeoutError(HTTPError):
40-
pass
40+
pass
4141

4242
err_dict = { 400 : BadRequestsError,
43-
401 : UnauthorizedError,
44-
403 : ForbiddenError,
45-
404 : NotFoundError,
46-
405 : MethodNotAllowedError,
47-
413 : PayloadTooLargeError,
48-
415 : UnsupportedMediaTypeError,
49-
429 : TooManyRequestsError,
50-
500 : InternalServerError,
51-
503 : ServiceUnavailableError,
52-
504 : GatewayTimeoutError
43+
401 : UnauthorizedError,
44+
403 : ForbiddenError,
45+
404 : NotFoundError,
46+
405 : MethodNotAllowedError,
47+
413 : PayloadTooLargeError,
48+
415 : UnsupportedMediaTypeError,
49+
429 : TooManyRequestsError,
50+
500 : InternalServerError,
51+
503 : ServiceUnavailableError,
52+
504 : GatewayTimeoutError
5353
}
5454

5555
def handle_error(error):
56-
try:
57-
exc = err_dict[error.code](error)
58-
except KeyError as e:
59-
return HTTPError(error)
60-
return exc
56+
try:
57+
exc = err_dict[error.code](error)
58+
except KeyError as e:
59+
return HTTPError(error)
60+
return exc

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def getRequires():
1313
return deps
1414

1515
base_url = 'https://github.com/sendgrid/'
16-
version = '2.2.1'
16+
version = '2.3.0'
1717
setup(
1818
name='python_http_client',
1919
version=version,

0 commit comments

Comments
 (0)