File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change
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
+ """
Original file line number Diff line number Diff line change 1
1
import json
2
2
3
+ from ..errors import EntryCreatedError , OperationCompletionError
4
+
3
5
4
6
class RS (object ):
5
7
def __init__ (self , raw ):
6
8
super (RS , self ).__init__ ()
7
9
self .raw = raw
8
10
9
11
12
+ # FIXME: need to improve and rework errors handling, add checks of err codes
10
13
class EntryCreatedRS (RS ):
11
14
def __init__ (self , raw ):
12
15
super (EntryCreatedRS , self ).__init__ (raw )
@@ -15,14 +18,14 @@ def __init__(self, raw):
15
18
def id (self ):
16
19
try :
17
20
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 ))
21
23
22
24
def as_dict (self ):
23
25
return {"id" : self .id }
24
26
25
27
28
+ # FIXME: need to improve and rework errors handling, add checks of err codes
26
29
class OperationCompletionRS (RS ):
27
30
def __init__ (self , raw ):
28
31
super (OperationCompletionRS , self ).__init__ (raw )
@@ -31,9 +34,8 @@ def __init__(self, raw):
31
34
def msg (self ):
32
35
try :
33
36
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 ))
37
39
38
40
def as_dict (self ):
39
41
return {"msg" : self .msg }
You can’t perform that action at this time.
0 commit comments