From 589297bceb8c31a153f878cd7a20d4acee24719a Mon Sep 17 00:00:00 2001 From: rawleyIfowler Date: Fri, 25 Feb 2022 20:01:06 -0600 Subject: [PATCH] added 500 error screen, and adjusted index: --- controllers/blog.go | 12 ++++++++++-- templates/index.tmpl | 2 +- templates/internal_server_error.tmpl | 4 ++++ templates/not_found.tmpl | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 templates/internal_server_error.tmpl diff --git a/controllers/blog.go b/controllers/blog.go index f4c9b3a..d95df4a 100644 --- a/controllers/blog.go +++ b/controllers/blog.go @@ -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 } diff --git a/templates/index.tmpl b/templates/index.tmpl index 375bcd0..f1d39c7 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -4,7 +4,7 @@ I am an independent software engineer, and self proclaimed systems administrator from Canada. Currently, I am pursuing a degree in Computer Science, with hopes of participating in a graduate program later down the road.

- I am a GNU/Linux and OpenBSD enthusiast. You'll find me active in the Debian Linux, Void Linux and OpenBSD communities. My favourite programming languages are Go and Clojure. You can check out my work on GitLab. Currently, I am working on my website, and an open-source community based blogging network called xrn. + I am a GNU/Linux and OpenBSD enthusiast. You'll find me active in the Debian Linux, Void Linux and OpenBSD communities. My favourite programming languages are Go and Clojure. Currently, I am working on my website, and an open-source community based blogging network called xrn. You can check out my work on GitLab.

When I'm not programming, I'm either reading, cooking, playing table-top games, or walking my dog. diff --git a/templates/internal_server_error.tmpl b/templates/internal_server_error.tmpl new file mode 100644 index 0000000..c3ab57e --- /dev/null +++ b/templates/internal_server_error.tmpl @@ -0,0 +1,4 @@ +{{ template "header.tmpl" . }} +

500 Internal server error :(

+

Click here to return home.

+{{ template "footer.tmpl" . }} diff --git a/templates/not_found.tmpl b/templates/not_found.tmpl index 61f17ba..1cccbaf 100644 --- a/templates/not_found.tmpl +++ b/templates/not_found.tmpl @@ -1,6 +1,6 @@ {{ template "header.tmpl" . }} -

404 Not Found :(

+

404 Not found :(

Click here to return home.