From d95437879153dd2de3be083c5b7bf2a5c9436e5b Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 2 Jul 2014 00:33:19 -0400 Subject: [PATCH] specify between torrent and http errors --- http/announce.go | 17 +++++++++++++---- http/scrape.go | 13 ++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/http/announce.go b/http/announce.go index 106a198..29de2e7 100644 --- a/http/announce.go +++ b/http/announce.go @@ -18,10 +18,13 @@ import ( func (t *Tracker) ServeAnnounce(w http.ResponseWriter, r *http.Request, p httprouter.Params) int { ann, err := models.NewAnnounce(t.cfg, r, p) - if err != nil { + if err == models.ErrMalformedRequest { fail(w, r, err) return http.StatusOK } + if err != nil { + return http.StatusInternalServerError + } conn, err := t.tp.Get() if err != nil { @@ -30,25 +33,31 @@ func (t *Tracker) ServeAnnounce(w http.ResponseWriter, r *http.Request, p httpro if t.cfg.Whitelist { err = conn.ClientWhitelisted(ann.ClientID()) - if err != nil { + if err == tracker.ErrClientUnapproved { fail(w, r, err) return http.StatusOK + } else if err != nil { + return http.StatusInternalServerError } } var user *models.User if t.cfg.Private { user, err = conn.FindUser(ann.Passkey) - if err != nil { + if err == tracker.ErrUserDNE { fail(w, r, err) return http.StatusOK + } else if err != nil { + return http.StatusInternalServerError } } torrent, err := conn.FindTorrent(ann.Infohash) - if err != nil { + if err == tracker.ErrTorrentDNE { fail(w, r, err) return http.StatusOK + } else if err != nil { + return http.StatusInternalServerError } peer := models.NewPeer(ann, user, torrent) diff --git a/http/scrape.go b/http/scrape.go index 948de5a..aad6c63 100644 --- a/http/scrape.go +++ b/http/scrape.go @@ -12,14 +12,17 @@ import ( "github.com/julienschmidt/httprouter" "github.com/chihaya/chihaya/bencode" + "github.com/chihaya/chihaya/drivers/tracker" "github.com/chihaya/chihaya/models" ) func (t *Tracker) ServeScrape(w http.ResponseWriter, r *http.Request, p httprouter.Params) int { scrape, err := models.NewScrape(t.cfg, r, p) - if err != nil { + if err == models.ErrMalformedRequest { fail(w, r, err) return http.StatusOK + } else if err != nil { + return http.StatusInternalServerError } conn, err := t.tp.Get() @@ -29,18 +32,22 @@ func (t *Tracker) ServeScrape(w http.ResponseWriter, r *http.Request, p httprout if t.cfg.Private { _, err = conn.FindUser(scrape.Passkey) - if err != nil { + if err == tracker.ErrUserDNE { fail(w, r, err) return http.StatusOK + } else if err != nil { + return http.StatusInternalServerError } } var torrents []*models.Torrent for _, infohash := range scrape.Infohashes { torrent, err := conn.FindTorrent(infohash) - if err != nil { + if err == tracker.ErrTorrentDNE { fail(w, r, err) return http.StatusOK + } else if err != nil { + return http.StatusInternalServerError } torrents = append(torrents, torrent) }