-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version Bump v2.3.0: #17 Added support for error handling
- Loading branch information
1 parent
1c71517
commit 45726d7
Showing
3 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters