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

Fixed error handling for bookmarks manager #137

Merged
merged 2 commits into from
Aug 30, 2024

Conversation

jjfreund
Copy link
Collaborator

No description provided.

iUserId, _ := strconv.Atoi(userId)
dbBookmarks = m.DbClient.GetBookmarksByUserID(iUserId)
iUserId, err := strconv.Atoi(userId)
if (err != nil) {
Copy link
Member

Choose a reason for hiding this comment

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

dont need to wrap this, normal to just do

if err != nil {
 stuff;
}

iUserId, err := strconv.Atoi(userId)
if (err != nil) {
log.Printf("%v", err)
writeStatus(w, http.StatusBadRequest)
Copy link
Member

Choose a reason for hiding this comment

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

This is a case where we can update the flow to provide an error message json body response

}

dbBookmark := m.DbClient.GetBookmarkByID(id)
dbBookmark, err := m.DbClient.GetBookmarkByID(id)
if (err != nil) {
Copy link
Member

Choose a reason for hiding this comment

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

We want to log the error here too, just the same flow as other cases

iUserId, err := strconv.Atoi(userId)
if (err != nil) {
log.Printf("%v", err)
writeStatus(w, http.StatusBadRequest)
Copy link
Member

Choose a reason for hiding this comment

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

I can add a test for any 400 cases

Copy link
Member

Choose a reason for hiding this comment

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

makes sense, we do want to bubble up errors, it was a mistake of me to not do that originally

@lgarofalo
Copy link
Member

Updated PR with responses to my comments

Copy link
Member

@richardxia richardxia left a comment

Choose a reason for hiding this comment

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

This LGTM, and thanks, @lgarofalo, for pushing up a commit to create a common Error struct for returning error responses with JSON bodies!

@lgarofalo lgarofalo merged commit 68541dc into main Aug 30, 2024
5 checks passed
@lgarofalo lgarofalo deleted the 125-error-handling-cleanup branch September 5, 2024 02:35
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