From c1b78bf43b1f20706c787061d7238e7acd8b5b2d Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 24 Dec 2025 19:20:25 +0100 Subject: Implements Must function and enhances Unauthorized handler Adds the Must function for error handling, simplifying code by allowing panic on errors. Improves the Unauthorized handler to ensure proper error reporting when writing responses. --- kcore/http.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'kcore/http.go') diff --git a/kcore/http.go b/kcore/http.go index e5d218b..f1a2b1a 100644 --- a/kcore/http.go +++ b/kcore/http.go @@ -26,3 +26,11 @@ func RenderPage(ctx context.Context, page templ.Component, w http.ResponseWriter _, err = buf.WriteTo(w) Expect(err, "error writing page to response writer") } + +func Unauthorized(w http.ResponseWriter, err error) { + w.WriteHeader(http.StatusUnauthorized) + if err != nil { + _, err = w.Write([]byte(err.Error())) + Expect(err, "error writing response") + } +} -- cgit v1.3