2
0
mirror of synced 2025-02-24 06:38:14 +00:00

Tidy up error handling on HTTP tracker client

This commit is contained in:
Matt Joiner 2015-03-27 17:18:45 +11:00
parent 64f833f3f0
commit 176f6e6aa4

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"log"
"net"
"net/http"
"net/url"
@ -79,10 +78,14 @@ func (me *client) Announce(ar *AnnounceRequest) (ret AnnounceResponse, err error
defer resp.Body.Close()
buf := bytes.Buffer{}
io.Copy(&buf, resp.Body)
log.Printf("%q", buf.Bytes())
if resp.StatusCode != 200 {
err = fmt.Errorf("response from tracker: %s: %s", resp.Status, buf.String())
return
}
var trackerResponse response
err = bencode.NewDecoder(&buf).Decode(&trackerResponse)
err = bencode.Unmarshal(buf.Bytes(), &trackerResponse)
if err != nil {
err = fmt.Errorf("error decoding %q: %s", buf.Bytes(), err)
return
}
if trackerResponse.FailureReason != "" {