mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-24 13:56:03 +03:00
Move api response status check before unmarshalling
This commit is contained in:
parent
ac3afd8f09
commit
62fbe75ce3
160
v1/client.go
160
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user