added 500 error screen, and adjusted index:

This commit is contained in:
rawleyIfowler
2022-02-25 20:01:06 -06:00
parent dca2efc52d
commit 589297bceb
4 changed files with 16 additions and 4 deletions

View File

@@ -49,7 +49,12 @@ func RegisterBlogGroup(r *gin.RouterGroup) {
}
func RenderBlogPage(c *gin.Context) {
c.HTML(http.StatusOK, "blog.tmpl", *GetAllBlogPosts())
posts := GetAllBlogPosts()
if posts == nil {
c.HTML(http.StatusInternalServerError, "internal_server_error.tmpl", gin.H{})
} else {
c.HTML(http.StatusOK, "blog.tmpl", posts)
}
}
func RenderIndividualBlogPost(c *gin.Context) {
@@ -118,7 +123,10 @@ func GetAllBlogPosts() *[]models.BlogPost {
var posts []models.BlogPost
// Select title, date, and url fields from the blog post records an store them in posts.
// This is so we don't grab the entire blog post when we render them on the overview page. Saves a couple ms.
db.Model(&models.BlogPost{}).Select("title, date, url").Take(&posts)
err := db.Model(&models.BlogPost{}).Select("title, date, url").Take(&posts).Error
if err != nil {
return nil
}
return &posts
}