From 62fbe75ce3c26c9f99e60d3253bbd22a0f0c45fb Mon Sep 17 00:00:00 2001 From: Vitaliy Chesnokov Date: Tue, 5 Mar 2019 18:15:32 +0300 Subject: [PATCH] Move api response status check before unmarshalling --- v1/client.go | 160 +++++++++++++++++++++++++-------------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/v1/client.go b/v1/client.go index 4f5169f..da677e0 100644 --- a/v1/client.go +++ b/v1/client.go @@ -51,14 +51,14 @@ func (c *MgClient) Bots(request BotsRequest) ([]BotsResponseItem, int, error) { return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -91,14 +91,14 @@ func (c *MgClient) Channels(request ChannelsRequest) ([]ChannelResponseItem, int return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -131,14 +131,14 @@ func (c *MgClient) Users(request UsersRequest) ([]UsersResponseItem, int, error) return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -171,14 +171,14 @@ func (c *MgClient) Customers(request CustomersRequest) ([]CustomersResponseItem, return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -211,14 +211,14 @@ func (c *MgClient) Chats(request ChatsRequest) ([]ChatResponseItem, int, error) return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -251,14 +251,14 @@ func (c *MgClient) Members(request MembersRequest) ([]MemberResponseItem, int, e return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -291,14 +291,14 @@ func (c *MgClient) Dialogs(request DialogsRequest) ([]DialogResponseItem, int, e return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -328,14 +328,14 @@ func (c *MgClient) DialogAssign(request DialogAssignRequest) (DialogAssignRespon return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -363,14 +363,14 @@ func (c *MgClient) DialogClose(request uint64) (map[string]interface{}, int, err return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -403,14 +403,14 @@ func (c *MgClient) Messages(request MessagesRequest) ([]MessagesResponseItem, in return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -444,14 +444,14 @@ func (c *MgClient) MessageSend(request MessageSendRequest) (MessageSendResponse, return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -482,14 +482,14 @@ func (c *MgClient) MessageEdit(request MessageEditRequest) (map[string]interface return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -517,14 +517,14 @@ func (c *MgClient) MessageDelete(request uint64) (map[string]interface{}, int, e return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -552,14 +552,14 @@ func (c *MgClient) Info(request InfoRequest) (map[string]interface{}, int, error return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -592,14 +592,14 @@ func (c *MgClient) Commands(request CommandsRequest) ([]CommandsResponseItem, in return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -633,14 +633,14 @@ func (c *MgClient) CommandEdit(request CommandEditRequest) (CommandsResponseItem return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -668,14 +668,14 @@ func (c *MgClient) CommandDelete(request string) (map[string]interface{}, int, e return resp, status, err } - if err := json.Unmarshal(data, &resp); err != nil { - return resp, status, err - } - if status > http.StatusCreated || status < http.StatusOK { return resp, status, c.Error(data) } + if err := json.Unmarshal(data, &resp); err != nil { + return resp, status, err + } + return resp, status, err } @@ -702,14 +702,14 @@ func (c *MgClient) GetFile(request string) (FullFileResponse, int, error) { return resp, status, err } - if e := json.Unmarshal(data, &resp); e != nil { - return resp, status, e - } - if status != http.StatusOK { return resp, status, c.Error(data) } + if e := json.Unmarshal(data, &resp); e != nil { + return resp, status, e + } + return resp, status, err } @@ -741,14 +741,14 @@ func (c *MgClient) UploadFile(request io.Reader) (UploadFileResponse, int, error return resp, status, err } - if e := json.Unmarshal(data, &resp); e != nil { - return resp, status, e - } - if status != http.StatusOK { return resp, status, c.Error(data) } + if e := json.Unmarshal(data, &resp); e != nil { + return resp, status, e + } + return resp, status, err } @@ -774,14 +774,14 @@ func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileRe return resp, status, err } - if e := json.Unmarshal(data, &resp); e != nil { - return resp, status, e - } - if status != http.StatusOK { return resp, status, c.Error(data) } + if e := json.Unmarshal(data, &resp); e != nil { + return resp, status, e + } + return resp, status, err }