more informative broker error messages (close #26)

This commit is contained in:
Serene Han 2016-03-09 14:37:29 -08:00
parent e5f284ca56
commit f91b8faa0a
2 changed files with 17 additions and 9 deletions

View file

@ -69,13 +69,21 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
} }
defer resp.Body.Close() defer resp.Body.Close()
log.Printf("BrokerChannel Response:\n%s\n\n", resp.Status) log.Printf("BrokerChannel Response:\n%s\n\n", resp.Status)
if http.StatusOK != resp.StatusCode {
return nil, errors.New("no answer from broker.") switch resp.StatusCode {
} case http.StatusOK:
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if nil != err { if nil != err {
return nil, err return nil, err
} }
answer := webrtc.DeserializeSessionDescription(string(body)) answer := webrtc.DeserializeSessionDescription(string(body))
return answer, nil 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.")
}
} }

View file

@ -237,7 +237,7 @@ func (c *webRTCConn) sendOfferToBroker() {
"\nFront URL: ", frontDomain) "\nFront URL: ", frontDomain)
answer, err := c.broker.Negotiate(offer) answer, err := c.broker.Negotiate(offer)
if nil != err || nil == answer { if nil != err || nil == answer {
log.Printf("BrokerChannel error: %s", err) log.Printf("BrokerChannel Error: %s", err)
answer = nil answer = nil
} }
c.answerChannel <- answer c.answerChannel <- answer