-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore: show a nicer error message when toggle a flag fails #179
Conversation
@@ -60,6 +60,35 @@ func confirmedFlag(flag flag) tea.Cmd { | |||
} | |||
} | |||
|
|||
type msgRequestError struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creates a new type to encapsulate converting from the API response to something we handle in messages and models.
existingFlag = e.Code == "conflict" | ||
if !existingFlag { | ||
return errMsg{err: errors.NewError(fmt.Sprintf("Error creating flag: %s. Press \"ctrl + c\" to quit.", e.Message))} | ||
msgRequestErr, err := newMsgRequestError(err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to handle this here since we don't consider a conflict an error, unlike the toggle flag command where a conflict is still an error.
return m, toggleFlag(m.client, m.accessToken, m.baseUri, m.flagKey, m.enabled) | ||
} | ||
case errMsg: | ||
msgRequestErr, err := newMsgRequestError(msg.err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We handle the error here since we're mapping the API error response to a model-specific response.
Requirements
Related issues
Provide links to any issues in this repository or elsewhere relating to this pull request.
Describe the solution you've provided
Provide a clear and concise description of what you expect to happen.
Describe alternatives you've considered
Provide a clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context about the pull request here.