move defers to a better place

This commit is contained in:
Rob Watson 2021-02-24 18:15:09 +01:00
parent b89a25f739
commit 60dbb8c5b2
1 changed files with 2 additions and 1 deletions

View File

@ -82,6 +82,7 @@ func (p *processor) acceptInvite(e *RawEvent) error {
if err != nil {
return fmt.Errorf("http error accepting invitation: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return p.handleErrorResponse(e, resp)
}
@ -106,6 +107,7 @@ func (p *processor) handleVerb(e *RawEvent, cmd, arg string) error {
if err != nil {
return fmt.Errorf("http error sending message: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return p.handleErrorResponse(e, resp)
}
@ -114,7 +116,6 @@ func (p *processor) handleVerb(e *RawEvent, cmd, arg string) error {
}
func (p *processor) handleErrorResponse(e *RawEvent, resp *http.Response) error {
defer resp.Body.Close()
var er errorResponse
if err := json.NewDecoder(resp.Body).Decode(&er); err != nil {
return fmt.Errorf("could not decode response: %v", err)