diff --git a/handlers/emoji_form.go b/handlers/emoji_form.go index d71d01f..ea2afe0 100644 --- a/handlers/emoji_form.go +++ b/handlers/emoji_form.go @@ -19,7 +19,7 @@ func GetEmojiForm(c *gin.Context) { // get emoji counts for each emoji emojiCounter, err := GetEmojis(postId) if err != nil { - c.HTML(http.StatusOK, "emoji_form.tmpl", gin.H{"error": "error getting the emoji counts"}) + c.AbortWithStatus(http.StatusInternalServerError) return } @@ -36,7 +36,7 @@ func PostEmojiForm(c *gin.Context) { // Check if parameters are missing if reactedPostId == "" || reaction == "" { - c.HTML(http.StatusBadRequest, "emoji_form_error.tmpl", gin.H{"errorMessage": "missing parameters"}) + c.AbortWithStatus(http.StatusBadRequest) } // Add the new emoji reaction to the database @@ -44,13 +44,13 @@ func PostEmojiForm(c *gin.Context) { DoUpdates: clause.AssignmentColumns([]string{"emoji"}), }).Create(&models.EmojiReaction{UserAnonIp: c.Request.RemoteAddr, Emoji: reaction, PostId: reactedPostId}) if result.Error != nil { - c.HTML(http.StatusOK, "emoji_form_error.tmpl", gin.H{"errorMessage": "error writing to database"}) + c.AbortWithStatus(http.StatusInternalServerError) } // get emoji counts for each emoji emojiCounter, err := GetEmojis(reactedPostId) if err != nil { - c.HTML(http.StatusOK, "emoji_form_error.tmpl", gin.H{"errorMessage": "error getting the emoji counts"}) + c.AbortWithStatus(http.StatusInternalServerError) } // Return the html with the updated emoji counter diff --git a/handlers/emoji_form_test.go b/handlers/emoji_form_test.go index ea80537..d9a95e7 100644 --- a/handlers/emoji_form_test.go +++ b/handlers/emoji_form_test.go @@ -73,7 +73,6 @@ func TestPostEmojiFormMissingParams(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, http.StatusBadRequest, w.Code) - assert.Contains(t, w.Body.String(), "missing parameters") } func TestGetEmojis(t *testing.T) { diff --git a/templates/emoji_form.tmpl b/templates/emoji_form.tmpl index a74ce72..0d39924 100644 --- a/templates/emoji_form.tmpl +++ b/templates/emoji_form.tmpl @@ -6,4 +6,4 @@ - +

{{ .errorMessage }}

diff --git a/templates/emoji_form_error.tmpl b/templates/emoji_form_error.tmpl deleted file mode 100644 index d8be0fd..0000000 --- a/templates/emoji_form_error.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -
- - - - - - -
-

{{ .errorMessage }}