Skip to content

Commit

Permalink
telnet sample fetch error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
glaslos committed Mar 30, 2017
1 parent dd6275e commit 1123eee
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions telnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"crypto/sha256"
"encoding/hex"
"errors"
"io/ioutil"
"math/rand"
"net"
Expand Down Expand Up @@ -78,7 +79,17 @@ func getSample(cmd string, g *Glutton) error {
g.logger.Errorf("[telnet ] getSample http error: %v", err)
return err
}
if resp.StatusCode != 200 {
err = errors.New("Non 200 status code on getSample")
g.logger.Errorf("[telnet ] getSample read http: %v", err)
return err
}
defer resp.Body.Close()
if resp.ContentLength <= 0 {
err = errors.New("Empty response body")
g.logger.Errorf("[telnet ] getSample read http: %v", err)
return err
}
g.logger.Infof("[telnet ] getSample body length: %d", resp.ContentLength)
bodyBuffer, err := ioutil.ReadAll(resp.Body)
if err != nil {
Expand Down

0 comments on commit 1123eee

Please sign in to comment.