use discriminated registration errors

This commit is contained in:
vyzo 2018-04-20 14:38:12 +03:00
parent 1506c04f1a
commit 7e5664ce7c
2 changed files with 7 additions and 1 deletions

View File

@ -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 fmt.Errorf("Registration failure: %s", status.String())
return RegistrationError(status)
}
return nil

View File

@ -13,6 +13,12 @@ const (
RendezvousProto = protocol.ID("/rendezvous/1.0.0")
)
type RegistrationError pb.Message_RegisterStatus
func (e RegistrationError) Error() string {
return pb.Message_RegisterStatus(e).String()
}
func newRegisterMessage(ns string, pi pstore.PeerInfo, ttl int) *pb.Message {
msg := new(pb.Message)
msg.Type = pb.Message_REGISTER.Enum()