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

chore: show a nicer error message when toggle a flag fails #179

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

dbolson
Copy link
Contributor

@dbolson dbolson commented Apr 15, 2024

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

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.

@@ -60,6 +60,35 @@ func confirmedFlag(flag flag) tea.Cmd {
}
}

type msgRequestError struct {
Copy link
Contributor Author

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())
Copy link
Contributor Author

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())
Copy link
Contributor Author

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.

@dbolson dbolson merged commit 6339137 into main Apr 15, 2024
2 checks passed
@dbolson dbolson deleted the sc-239301/human-readable-flag-toggle-error branch April 15, 2024 18:33
@sunnyguduru sunnyguduru mentioned this pull request Apr 15, 2024
3 tasks
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.

2 participants