Skip to content

Add logic to not return error in DeleteUser when no user is found #80

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

Merged
merged 2 commits into from
May 3, 2022
Merged
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
14 changes: 10 additions & 4 deletions client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"fmt"
"log"
"strings"
)

type Credentials struct {
Expand Down Expand Up @@ -263,10 +264,15 @@ func (client *Client) DeleteUser(userName string) error {
Method: "DELETE",
}

_, err := client.RequestAPI(&opts)
if err != nil {
return err
}
// The API will return a 500 error if the user cannot be found
// In this case the DeleteUser function should not return an error.
// Return error only if the body of the return message does not contain "User does not exist"
res, err := client.RequestAPI(&opts)
if err != nil {
if !strings.Contains(string(res), "User does not exist") {
return err
}
}

return nil
}
Expand Down