44 "context"
55 "encoding/json"
66 "fmt"
7+ "net/http"
78 "net/url"
89 "strconv"
910 "time"
@@ -19,13 +20,17 @@ func (r *Client) CreateAnnotation(ctx context.Context, a CreateAnnotationRequest
1920 raw []byte
2021 resp StatusMessage
2122 err error
23+ code int
2224 )
2325 if raw , err = json .Marshal (a ); err != nil {
2426 return StatusMessage {}, errors .Wrap (err , "marshal request" )
2527 }
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 {
2729 return StatusMessage {}, errors .Wrap (err , "create annotation" )
2830 }
31+ if code != http .StatusOK {
32+ return StatusMessage {}, fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
33+ }
2934 if err = json .Unmarshal (raw , & resp ); err != nil {
3035 return StatusMessage {}, errors .Wrap (err , "unmarshal response message" )
3136 }
@@ -38,13 +43,17 @@ func (r *Client) PatchAnnotation(ctx context.Context, id uint, a PatchAnnotation
3843 raw []byte
3944 resp StatusMessage
4045 err error
46+ code int
4147 )
4248 if raw , err = json .Marshal (a ); err != nil {
4349 return StatusMessage {}, errors .Wrap (err , "marshal request" )
4450 }
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 {
4652 return StatusMessage {}, errors .Wrap (err , "patch annotation" )
4753 }
54+ if code != http .StatusOK {
55+ return StatusMessage {}, fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
56+ }
4857 if err = json .Unmarshal (raw , & resp ); err != nil {
4958 return StatusMessage {}, errors .Wrap (err , "unmarshal response message" )
5059 }
@@ -58,15 +67,19 @@ func (r *Client) GetAnnotations(ctx context.Context, params ...GetAnnotationsPar
5867 err error
5968 resp []AnnotationResponse
6069 requestParams = make (url.Values )
70+ code int
6171 )
6272
6373 for _ , p := range params {
6474 p (requestParams )
6575 }
6676
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 {
6878 return nil , errors .Wrap (err , "get annotations" )
6979 }
80+ if code != http .StatusOK {
81+ return nil , fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
82+ }
7083 if err = json .Unmarshal (raw , & resp ); err != nil {
7184 return nil , errors .Wrap (err , "unmarshal response message" )
7285 }
@@ -79,11 +92,15 @@ func (r *Client) DeleteAnnotation(ctx context.Context, id uint) (StatusMessage,
7992 raw []byte
8093 err error
8194 resp StatusMessage
95+ code int
8296 )
8397
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 {
8599 return StatusMessage {}, errors .Wrap (err , "delete annotation" )
86100 }
101+ if code != http .StatusOK {
102+ return StatusMessage {}, fmt .Errorf ("HTTP error %d: returns %s" , code , raw )
103+ }
87104 if err = json .Unmarshal (raw , & resp ); err != nil {
88105 return StatusMessage {}, errors .Wrap (err , "unmarshal response message" )
89106 }
0 commit comments