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 all 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
8 changes: 5 additions & 3 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,13 @@ auth0 apis delete <id>`,
}

return ansi.Spinner("Deleting API", func() error {
err := cli.api.ResourceServer.Delete(url.PathEscape(inputs.ID))
_, err := cli.api.ResourceServer.Read(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 fmt.Errorf("Unable to delete API. The specified Id: %v doesn't exist", inputs.ID)
}
return nil

return cli.api.ResourceServer.Delete(url.PathEscape(inputs.ID))
})
},
}
Expand Down
8 changes: 7 additions & 1 deletion internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,13 @@ auth0 apps delete <id>`,
}
}

return ansi.Spinner("Deleting application", func() error {
return ansi.Spinner("Deleting Application", func() error {
_, err := cli.api.Client.Read(inputs.ID)

if err != nil {
return fmt.Errorf("Unable to delete application. The specified Id: %v doesn't exist", inputs.ID)
}

return cli.api.Client.Delete(inputs.ID)
})
},
Expand Down
14 changes: 7 additions & 7 deletions internal/cli/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ auth0 rules delete <rule-id>`,
}
}

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

if err != nil {
return err
}
if err != nil {
return fmt.Errorf("Unable to delete application. The specified Id: %v doesn't exist", inputs.ID)
}

return nil
return cli.api.Rule.Delete(inputs.ID)
})
},
}

Expand Down