Skip to content

Commit

Permalink
updated error messages for apis command
Browse files Browse the repository at this point in the history
  • Loading branch information
morganelle committed Mar 2, 2021
1 parent db4fd08 commit a8fbf79
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"errors"
"fmt"
"strings"

"github.com/auth0/auth0-cli/internal/ansi"
Expand Down Expand Up @@ -66,7 +67,7 @@ Lists your existing APIs. To create one try:
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}

cli.renderer.ApiList(list.ResourceServers)
Expand Down Expand Up @@ -99,10 +100,10 @@ auth0 apis show <id>
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -117,7 +118,7 @@ auth0 apis show <id>
})

if err != nil {
return err
return fmt.Errorf("Unable to find an API with id %s: %w", inputs.ID, err)
}

cli.renderer.ApiShow(api)
Expand Down Expand Up @@ -153,7 +154,7 @@ auth0 apis create --name myapi --identifier http://my-api
true)

if err := prompt.AskOne(input, &flags); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

Expand All @@ -164,15 +165,15 @@ auth0 apis create --name myapi --identifier http://my-api
true)

if err := prompt.AskOne(input, &flags); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

if shouldPrompt(cmd, apiScopes) {
input := prompt.TextInput(apiScopes, "Scopes:", "Space-separated list of scopes.", false)

if err := prompt.AskOne(input, &flags); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

Expand All @@ -190,7 +191,7 @@ auth0 apis create --name myapi --identifier http://my-api
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred while attempting to create an API with name %s and identifier %s : %w", flags.Name, flags.Identifier, err)
}

cli.renderer.ApiCreate(api)
Expand Down Expand Up @@ -230,10 +231,10 @@ auth0 apis update <id> --name myapi
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -243,15 +244,15 @@ auth0 apis update <id> --name myapi
input := prompt.TextInput(apiName, "Name:", "Name of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

if shouldPrompt(cmd, apiScopes) {
input := prompt.TextInput(apiScopes, "Scopes:", "Space-separated list of scopes.", false)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
}

Expand All @@ -266,7 +267,7 @@ auth0 apis update <id> --name myapi
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred while updating the API with id %s: %w", inputs.ID, err)
}

cli.renderer.ApiUpdate(api)
Expand Down Expand Up @@ -302,10 +303,10 @@ auth0 apis delete <id>
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -318,7 +319,11 @@ auth0 apis delete <id>
}

return ansi.Spinner("Deleting API", func() error {
return cli.api.ResourceServer.Delete(inputs.ID)
err := cli.api.ResourceServer.Delete(inputs.ID)
if err != nil {
return fmt.Errorf("An unexpected error occurred while attempting to delete an API with id %s: %w", inputs.ID, err)
}
return nil
})
},
}
Expand Down Expand Up @@ -348,10 +353,10 @@ auth0 apis scopes list <id>
input := prompt.TextInput(apiID, "Id:", "Id of the API.", true)

if err := prompt.AskOne(input, &inputs); err != nil {
return err
return fmt.Errorf("An unexpected error occurred: %w", err)
}
} else {
return errors.New("missing API id")
return errors.New("Please include an API id")
}
} else {
inputs.ID = args[0]
Expand All @@ -366,7 +371,7 @@ auth0 apis scopes list <id>
})

if err != nil {
return err
return fmt.Errorf("An unexpected error occurred while getting scopes for the API with id %s: %w", inputs.ID, err)
}

cli.renderer.ScopesList(api.GetName(), api.Scopes)
Expand Down

0 comments on commit a8fbf79

Please sign in to comment.