Skip to content

Commit f30085c

Browse files
committed
improve error message for part 1 issue #10
1 parent 0554069 commit f30085c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

reportportal_client/errors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Error(Exception):
2+
"""General exception for package."""
3+
4+
5+
class EntryCreatedError(Error):
6+
"""Represents error in case no entry is created.
7+
8+
No 'id' in the json response.
9+
"""
10+
11+
12+
class OperationCompletionError(Error):
13+
"""Represents error in case of operation failure.
14+
15+
No 'msg' in the json response.
16+
"""

reportportal_client/model/response.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import json
22

3+
from ..errors import EntryCreatedError, OperationCompletionError
4+
35

46
class RS(object):
57
def __init__(self, raw):
68
super(RS, self).__init__()
79
self.raw = raw
810

911

12+
# FIXME: need to improve and rework errors handling, add checks of err codes
1013
class EntryCreatedRS(RS):
1114
def __init__(self, raw):
1215
super(EntryCreatedRS, self).__init__(raw)
@@ -15,14 +18,14 @@ def __init__(self, raw):
1518
def id(self):
1619
try:
1720
return json.loads(self.raw)["id"]
18-
except KeyError as error:
19-
error.message += "Raw: {0}".format(self.raw)
20-
raise
21+
except KeyError:
22+
raise EntryCreatedError("raw: {0}".format(self.raw))
2123

2224
def as_dict(self):
2325
return {"id": self.id}
2426

2527

28+
# FIXME: need to improve and rework errors handling, add checks of err codes
2629
class OperationCompletionRS(RS):
2730
def __init__(self, raw):
2831
super(OperationCompletionRS, self).__init__(raw)
@@ -31,9 +34,8 @@ def __init__(self, raw):
3134
def msg(self):
3235
try:
3336
return json.loads(self.raw)["msg"]
34-
except KeyError as error:
35-
error.message += "Raw: {0}".format(self.raw)
36-
raise
37+
except KeyError:
38+
raise OperationCompletionError("raw: {0}".format(self.raw))
3739

3840
def as_dict(self):
3941
return {"msg": self.msg}

0 commit comments

Comments
 (0)