Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI-122] throw an error for delete commands if item doesn't exit #239

Merged
merged 5 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,21 @@ auth0 apis delete <id>`,
}
}

return ansi.Spinner("Deleting API", func() error {
err := cli.api.ResourceServer.Delete(url.PathEscape(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
var list *management.ResourceServer
err := ansi.Waiting(func() error {
var err error
list, err = cli.api.ResourceServer.Read(url.PathEscape(inputs.ID))
return err
})
_ = list

if err != nil {
return fmt.Errorf("Unable to delete API. The specified Id: %v doesn't exist", inputs.ID)
} else {
return ansi.Spinner("Deleting API", func() error {
return cli.api.ResourceServer.Delete(url.PathEscape(inputs.ID))
})
}
},
}

Expand Down
16 changes: 14 additions & 2 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,21 @@ auth0 apps delete <id>`,
}
}

return ansi.Spinner("Deleting application", func() error {
return cli.api.Client.Delete(inputs.ID)
var list *management.Client
err := ansi.Waiting(func() error {
var err error
list, err = cli.api.Client.Read(inputs.ID)
return err
})
_ = list

if err != nil {
return fmt.Errorf("Unable to delete application. The specified Id: %v doesn't exist", inputs.ID)
} else {
return ansi.Spinner("Deleting Application", func() error {
return cli.api.Client.Delete(inputs.ID)
})
}
},
}

Expand Down
16 changes: 11 additions & 5 deletions internal/cli/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,21 @@ auth0 rules delete <rule-id>`,
}
}

err := ansi.Spinner("Deleting rule", func() error {
return cli.api.Rule.Delete(inputs.ID)
var rule *management.Rule
err := ansi.Waiting(func() error {
var err error
rule, err = cli.api.Rule.Read(inputs.ID)
return err
})
_ = rule

if err != nil {
return err
return fmt.Errorf("Unable to delete rule. The specified Id: %v doesn't exist", inputs.ID)
} else {
return ansi.Spinner("Deleting rule", func() error {
return cli.api.Rule.Delete(inputs.ID)
})
}

return nil
},
}

Expand Down