From 45726d7e2db698fc420103b7141130221c8a7171 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Tue, 20 Jun 2017 19:42:16 -0700 Subject: [PATCH] Version Bump v2.3.0: #17 Added support for error handling --- CHANGELOG.md | 5 +++ python_http_client/exceptions.py | 64 ++++++++++++++++---------------- setup.py | 2 +- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38ad414..72b47ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/python_http_client/exceptions.py b/python_http_client/exceptions.py index d61d390..8f714e5 100644 --- a/python_http_client/exceptions.py +++ b/python_http_client/exceptions.py @@ -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 diff --git a/setup.py b/setup.py index 4095fa8..6bf7eee 100755 --- a/setup.py +++ b/setup.py @@ -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,