Skip to content

[CLI-1983] parse and catch all v2 api call response error message#1444

Merged
MuweiHe merged 4 commits intomainfrom
CLI-1983
Sep 23, 2022
Merged

[CLI-1983] parse and catch all v2 api call response error message#1444
MuweiHe merged 4 commits intomainfrom
CLI-1983

Conversation

@MuweiHe
Copy link
Contributor

@MuweiHe MuweiHe commented Sep 22, 2022

Checklist

  1. [CRUCIAL] Is the change for CP or CCloud functionalities that are already live in prod?
    • yes: ok

What

connect team caught that 400 error message of pausing a connect is not caught and only printing out the error code. In this pr I made changes to parse and print all v2 api call response error messages.
Notice that there are 3 different structure of responses of v2 api's (something teams should work on to unify):
Errors with a list of error details, error message, error with a string of code and message. So we need 3 structs to unmarshall them all.

References

Test & Review

mhe@C02DV0KVMD6T cli % confluent connect pause lcc-7knq9o             
Error: Cannot pause connector lcc-7knq9o as it is still in provisioning state: 400 Bad Request

mhe@C02DV0KVMD6T cli % confluent api-key delete dwhaui
Error: error getting API key: Forbidden Access: unknown API key dwhaui

Suggestions:
    Ensure the API key exists and has not been deleted, or create a new API key via `confluent api-key create`.


@MuweiHe MuweiHe marked this pull request as ready for review September 22, 2022 07:04
@MuweiHe MuweiHe requested a review from a team as a code owner September 22, 2022 07:04
Comment on lines +175 to +177
return Wrap(err, strings.TrimFunc(resBody.Error.Message, func(c rune) bool {
return c == rune('.') || c == rune('\n')
}))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It blows my mind why you'd ever end an error with a newline... Anyways, let's do this in two separate steps instead? 1. Trim the error message, 2. Wrap the error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, can we use strings.TrimRight() instead of strings.TrimFunc()? If strings.TrimRight() doesn't like newlines, maybe we could use strings.TrimSpace() instead? (The runes are confusing, and needing a trim function seems like overkill)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some errors only have . or \n and some have both. using 2 nested trim looks kinda not clean to me?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@MuweiHe MuweiHe merged commit 483de0f into main Sep 23, 2022
@MuweiHe MuweiHe deleted the CLI-1983 branch September 23, 2022 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants