move defers to a better place
This commit is contained in:
parent
b89a25f739
commit
60dbb8c5b2
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue