Merge pull request #27 from moriony/fix-response-status-check

Move api response status check before unmarshalling
This commit is contained in:
Alex Lushpai 2019-03-06 12:54:20 +03:00 committed by GitHub
commit 0dc56b83e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,14 +51,14 @@ func (c *MgClient) Bots(request BotsRequest) ([]BotsResponseItem, int, error) {
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err return resp, status, err
} }
@ -91,14 +91,14 @@ func (c *MgClient) Channels(request ChannelsRequest) ([]ChannelResponseItem, int
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err return resp, status, err
} }
@ -171,14 +171,14 @@ func (c *MgClient) Customers(request CustomersRequest) ([]CustomersResponseItem,
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err return resp, status, err
} }
@ -328,14 +328,14 @@ func (c *MgClient) DialogAssign(request DialogAssignRequest) (DialogAssignRespon
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err return resp, status, err
} }
@ -403,14 +403,14 @@ func (c *MgClient) Messages(request MessagesRequest) ([]MessagesResponseItem, in
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err return resp, status, err
} }
@ -444,14 +444,14 @@ func (c *MgClient) MessageSend(request MessageSendRequest) (MessageSendResponse,
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err return resp, status, err
} }
@ -592,14 +592,14 @@ func (c *MgClient) Commands(request CommandsRequest) ([]CommandsResponseItem, in
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err return resp, status, err
} }
@ -633,14 +633,14 @@ func (c *MgClient) CommandEdit(request CommandEditRequest) (CommandsResponseItem
return resp, status, err return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK { if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
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 return resp, status, err
} }
if e := json.Unmarshal(data, &resp); e != nil {
return resp, status, e
}
if status != http.StatusOK { if status != http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if e := json.Unmarshal(data, &resp); e != nil {
return resp, status, e
}
return resp, status, err return resp, status, err
} }
@ -741,14 +741,14 @@ func (c *MgClient) UploadFile(request io.Reader) (UploadFileResponse, int, error
return resp, status, err return resp, status, err
} }
if e := json.Unmarshal(data, &resp); e != nil {
return resp, status, e
}
if status != http.StatusOK { if status != http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if e := json.Unmarshal(data, &resp); e != nil {
return resp, status, e
}
return resp, status, err return resp, status, err
} }
@ -774,14 +774,14 @@ func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileRe
return resp, status, err return resp, status, err
} }
if e := json.Unmarshal(data, &resp); e != nil {
return resp, status, e
}
if status != http.StatusOK { if status != http.StatusOK {
return resp, status, c.Error(data) return resp, status, c.Error(data)
} }
if e := json.Unmarshal(data, &resp); e != nil {
return resp, status, e
}
return resp, status, err return resp, status, err
} }