From 393cc1f3c078ec2e279fb9c64fe5a151b5ede1a7 Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Wed, 31 Jul 2024 20:48:49 -0400 Subject: [PATCH] Better error handling --- main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 3c276d2..37b47f8 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "html/template" + "log" "net/http" "github.com/go-chi/chi/v5" @@ -12,11 +13,15 @@ func homeHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf8") tpl, err := template.ParseFiles("templates/home.gohtml") if err != nil { - panic(err) + log.Printf("Error parsing template: %v", err) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return } err = tpl.Execute(w, nil) if err != nil { - panic(err) + log.Printf("Error executing template: %v", err) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return } } func contactHandler(w http.ResponseWriter, r *http.Request) {