[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] more informative broker error messages (close #26)



commit f91b8faa0aef760a9356f02bbb412304d7e09e78
Author: Serene Han <keroserene+git@xxxxxxxxx>
Date:   Wed Mar 9 14:37:29 2016 -0800

    more informative broker error messages (close #26)
---
 client/rendezvous.go | 24 ++++++++++++++++--------
 client/webrtc.go     |  2 +-
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/client/rendezvous.go b/client/rendezvous.go
index 29969f0..b764bc3 100644
--- a/client/rendezvous.go
+++ b/client/rendezvous.go
@@ -69,13 +69,21 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
 	}
 	defer resp.Body.Close()
 	log.Printf("BrokerChannel Response:\n%s\n\n", resp.Status)
-	if http.StatusOK != resp.StatusCode {
-		return nil, errors.New("no answer from broker.")
-	}
-	body, err := ioutil.ReadAll(resp.Body)
-	if nil != err {
-		return nil, err
+
+	switch resp.StatusCode {
+	case http.StatusOK:
+		body, err := ioutil.ReadAll(resp.Body)
+		if nil != err {
+			return nil, err
+		}
+		answer := webrtc.DeserializeSessionDescription(string(body))
+		return answer, nil
+
+	case http.StatusServiceUnavailable:
+		return nil, errors.New("No snowflake proxies currently available.")
+	case http.StatusBadRequest:
+		return nil, errors.New("You sent an invalid offer in the request.")
+	default:
+		return nil, errors.New("Unexpected error, no answer.")
 	}
-	answer := webrtc.DeserializeSessionDescription(string(body))
-	return answer, nil
 }
diff --git a/client/webrtc.go b/client/webrtc.go
index a77d4a8..d4c0272 100644
--- a/client/webrtc.go
+++ b/client/webrtc.go
@@ -237,7 +237,7 @@ func (c *webRTCConn) sendOfferToBroker() {
 		"\nFront URL:  ", frontDomain)
 	answer, err := c.broker.Negotiate(offer)
 	if nil != err || nil == answer {
-		log.Printf("BrokerChannel error: %s", err)
+		log.Printf("BrokerChannel Error: %s", err)
 		answer = nil
 	}
 	c.answerChannel <- answer



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits