Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit 0a2d75f

Browse files
committed
Fix strange __getattr__ behaviour in exception handling
issue #5
1 parent 7d78d4c commit 0a2d75f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

billogram_api.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ class BillogramAPIError(Exception):
4646
"Base class for errors from the Billogram API"
4747
def __init__(self, message, **kwargs):
4848
super(BillogramAPIError, self).__init__(message)
49-
for k, v in kwargs.items():
50-
if v is not None:
51-
setattr(self, k, v)
5249

53-
def __getattr__(self, name):
54-
# called just for non-existent keys, just pretend those are blank
55-
# makes handling of keyword arguments to constructor easier
56-
return None
50+
self.field = kwargs.get('field', None)
51+
self.field_path = kwargs.get('field_path', None)
52+
53+
self.extra_data = kwargs
54+
if 'field' in self.extra_data:
55+
del self.extra_data['field']
56+
if 'field_path' in self.extra_data:
57+
del self.extra_data['field_path']
58+
if not self.extra_data:
59+
self.extra_data = None
60+
5761

5862
class ServiceMalfunctioningError(BillogramAPIError):
5963
"The Billogram API service seems to be malfunctioning"

0 commit comments

Comments
 (0)