Azure: Refactor login errors

Signed-off-by: Christopher Crone <christopher.crone@docker.com>
This commit is contained in:
Christopher Crone 2020-06-04 10:20:39 +02:00
parent 35789ace12
commit e5335adedd
4 changed files with 22 additions and 22 deletions

View file

@ -1,6 +1,7 @@
package login
import (
"context"
"fmt"
"strings"
@ -9,6 +10,7 @@ import (
"github.com/docker/api/cli/dockerclassic"
"github.com/docker/api/client"
"github.com/docker/api/errdefs"
)
// Command returns the login command
@ -46,15 +48,15 @@ func cloudLogin(cmd *cobra.Command, backendType string) error {
ctx := cmd.Context()
cs, err := client.GetCloudService(ctx, backendType)
if err != nil {
return errors.Wrap(err, "cannot connect to backend")
return errors.Wrap(errdefs.ErrLoginFailed, "cannot connect to backend")
}
err = cs.Login(ctx, nil)
if errors.Is(err, context.Canceled) {
return errors.New("login canceled")
}
if err != nil {
return err
}
if cmd.Context().Err() != nil {
return errors.New("login canceled")
}
fmt.Println("login successful")
return nil
}