Skip to content

Commit 21bffd0

Browse files
author
Alexander.Iljushkin
authored
Merge pull request #11 from krasoffski/errors
Improve error message for part 1 issue #10
2 parents 1be2ce3 + d9da792 commit 21bffd0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
22

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

46
class RS(object):
57
def __init__(self, raw):
@@ -15,9 +17,8 @@ def __init__(self, raw):
1517
def id(self):
1618
try:
1719
return json.loads(self.raw)["id"]
18-
except KeyError as error:
19-
error.message += "Raw: {0}".format(self.raw)
20-
raise
20+
except KeyError:
21+
raise EntryCreatedError("raw: {0}".format(self.raw))
2122

2223
def as_dict(self):
2324
return {"id": self.id}
@@ -31,9 +32,8 @@ def __init__(self, raw):
3132
def msg(self):
3233
try:
3334
return json.loads(self.raw)["msg"]
34-
except KeyError as error:
35-
error.message += "Raw: {0}".format(self.raw)
36-
raise
35+
except KeyError:
36+
raise OperationCompletionError("raw: {0}".format(self.raw))
3737

3838
def as_dict(self):
3939
return {"msg": self.msg}

0 commit comments

Comments
 (0)