diff --git a/client.go b/client.go index 2ed61a5..dc629aa 100644 --- a/client.go +++ b/client.go @@ -66,7 +66,7 @@ func (cli *client) Register(ctx context.Context, ns string, ttl int) error { status := res.GetRegisterResponse().GetStatus() if status != pb.Message_OK { - return RegistrationError(status) + return RendezvousError{Status: status, Text: res.GetRegisterResponse().GetStatusText()} } return nil @@ -142,6 +142,11 @@ func discoverQuery(ns string, limit int, cookie []byte, r ggio.Reader, w ggio.Wr return nil, nil, fmt.Errorf("Unexpected response: %s", res.GetType().String()) } + status := res.GetDiscoverResponse().GetStatus() + if status != pb.Message_OK { + return nil, nil, RendezvousError{Status: status, Text: res.GetDiscoverResponse().GetStatusText()} + } + regs := res.GetDiscoverResponse().GetRegistrations() pinfos := make([]pstore.PeerInfo, 0, len(regs)) for _, reg := range regs { diff --git a/proto.go b/proto.go index 1b1ae0e..ae3941d 100644 --- a/proto.go +++ b/proto.go @@ -1,6 +1,8 @@ package rendezvous import ( + "fmt" + pb "github.com/libp2p/go-libp2p-rendezvous/pb" peer "github.com/libp2p/go-libp2p-peer" @@ -13,10 +15,13 @@ const ( RendezvousProto = protocol.ID("/rendezvous/1.0.0") ) -type RegistrationError pb.Message_RegisterStatus +type RendezvousError struct { + Status pb.Message_ResponseStatus + Text string +} -func (e RegistrationError) Error() string { - return "Registration error: " + pb.Message_RegisterStatus(e).String() +func (e RendezvousError) Error() string { + return fmt.Sprintf("Rendezvous error: %s (%s)", e.Text, pb.Message_ResponseStatus(e.Status).String()) } func newRegisterMessage(ns string, pi pstore.PeerInfo, ttl int) *pb.Message {