Skip to content

Commit 20c20c7

Browse files
committed
Fixed Error handlers
1 parent 5c014ba commit 20c20c7

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

kepconfig/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,10 @@ def __connect(self,request_obj):
441441
except error.HTTPError as err:
442442
payload = json.loads(codecs.decode(err.read(),'utf-8-sig'))
443443
# print('HTTP Code: {}\n{}'.format(err.code,payload), file=sys.stderr)
444-
raise KepHTTPError(err.url, err.code, err.msg, err.hdrs, payload)
444+
raise KepHTTPError(url=err.url, code=err.code, msg=err.msg, hdrs=err.hdrs, payload=payload)
445445
except error.URLError as err:
446446
# print('URLError: {} URL: {}'.format(err.reason, request_obj.get_full_url()), file=sys.stderr)
447-
raise KepURLError(err.reason, request_obj.get_full_url())
447+
raise KepURLError(msg=err.reason, url=request_obj.get_full_url())
448448

449449
# Fucntion used to ensure special characters are handled in the URL
450450
# Ex: Space will be turned to %20

kepconfig/error.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
r"""`error` Exception classes raised by Kepconfig.
9-
Includes KepURLError and KepHTTPError
9+
Includes KepError, KepURLError and KepHTTPError
1010
"""
1111

1212
__all__ = ['KepError', 'KepURLError', 'KepHTTPError']
@@ -24,10 +24,13 @@ def __str__(self):
2424
class KepURLError(KepError):
2525
'''Exception class raised by Kepconfig that inherits responses from the urllib URLError exceptions.
2626
'''
27-
def __init__(self, reason, url):
28-
KepError.__init__(self)
29-
self.reason = reason
27+
def __init__(self, url=None, *args, **kwargs):
28+
super().__init__(*args, **kwargs)
3029
self.url = url
30+
31+
@property
32+
def reason(self):
33+
return self.msg
3134

3235
def __str__(self):
3336
return '<urlopen error %s>' % self.reason
@@ -39,8 +42,8 @@ class KepHTTPError(KepError):
3942
code, headers, and a body. In some contexts,an application may want to
4043
handle an exception like a regular response.
4144
'''
42-
def __init__(self, url, code, msg, hdrs, payload):
43-
KepError.__init__(self, msg)
45+
def __init__(self, url=None, code=None, hdrs=None, payload=None, *args, **kwargs):
46+
super().__init__(*args, **kwargs)
4447
self.url = url
4548
self.code = code
4649
self.hdrs = hdrs

0 commit comments

Comments
 (0)