4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+ "net/http"
7
8
"net/url"
8
9
"strconv"
9
10
"time"
@@ -19,13 +20,17 @@ func (r *Client) CreateAnnotation(ctx context.Context, a CreateAnnotationRequest
19
20
raw []byte
20
21
resp StatusMessage
21
22
err error
23
+ code int
22
24
)
23
25
if raw , err = json .Marshal (a ); err != nil {
24
26
return StatusMessage {}, errors .Wrap (err , "marshal request" )
25
27
}
26
- if raw , _ , err = r .post (ctx , "api/annotations" , nil , raw ); err != nil {
28
+ if raw , code , err = r .post (ctx , "api/annotations" , nil , raw ); err != nil {
27
29
return StatusMessage {}, errors .Wrap (err , "create annotation" )
28
30
}
31
+ if code != http .StatusOK {
32
+ return StatusMessage {}, fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
33
+ }
29
34
if err = json .Unmarshal (raw , & resp ); err != nil {
30
35
return StatusMessage {}, errors .Wrap (err , "unmarshal response message" )
31
36
}
@@ -38,13 +43,17 @@ func (r *Client) PatchAnnotation(ctx context.Context, id uint, a PatchAnnotation
38
43
raw []byte
39
44
resp StatusMessage
40
45
err error
46
+ code int
41
47
)
42
48
if raw , err = json .Marshal (a ); err != nil {
43
49
return StatusMessage {}, errors .Wrap (err , "marshal request" )
44
50
}
45
- if raw , _ , err = r .patch (ctx , fmt .Sprintf ("api/annotations/%d" , id ), nil , raw ); err != nil {
51
+ if raw , code , err = r .patch (ctx , fmt .Sprintf ("api/annotations/%d" , id ), nil , raw ); err != nil {
46
52
return StatusMessage {}, errors .Wrap (err , "patch annotation" )
47
53
}
54
+ if code != http .StatusOK {
55
+ return StatusMessage {}, fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
56
+ }
48
57
if err = json .Unmarshal (raw , & resp ); err != nil {
49
58
return StatusMessage {}, errors .Wrap (err , "unmarshal response message" )
50
59
}
@@ -58,15 +67,19 @@ func (r *Client) GetAnnotations(ctx context.Context, params ...GetAnnotationsPar
58
67
err error
59
68
resp []AnnotationResponse
60
69
requestParams = make (url.Values )
70
+ code int
61
71
)
62
72
63
73
for _ , p := range params {
64
74
p (requestParams )
65
75
}
66
76
67
- if raw , _ , err = r .get (ctx , "api/annotations" , requestParams ); err != nil {
77
+ if raw , code , err = r .get (ctx , "api/annotations" , requestParams ); err != nil {
68
78
return nil , errors .Wrap (err , "get annotations" )
69
79
}
80
+ if code != http .StatusOK {
81
+ return nil , fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
82
+ }
70
83
if err = json .Unmarshal (raw , & resp ); err != nil {
71
84
return nil , errors .Wrap (err , "unmarshal response message" )
72
85
}
@@ -79,11 +92,15 @@ func (r *Client) DeleteAnnotation(ctx context.Context, id uint) (StatusMessage,
79
92
raw []byte
80
93
err error
81
94
resp StatusMessage
95
+ code int
82
96
)
83
97
84
- if raw , _ , err = r .delete (ctx , fmt .Sprintf ("api/annotations/%d" , id )); err != nil {
98
+ if raw , code , err = r .delete (ctx , fmt .Sprintf ("api/annotations/%d" , id )); err != nil {
85
99
return StatusMessage {}, errors .Wrap (err , "delete annotation" )
86
100
}
101
+ if code != http .StatusOK {
102
+ return StatusMessage {}, fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
103
+ }
87
104
if err = json .Unmarshal (raw , & resp ); err != nil {
88
105
return StatusMessage {}, errors .Wrap (err , "unmarshal response message" )
89
106
}
0 commit comments