This commit is contained in:
csehviktor
2025-08-01 05:52:06 +02:00
commit aae5a0e0fb
16 changed files with 656 additions and 0 deletions

23
handler/errors.go Normal file
View File

@@ -0,0 +1,23 @@
package handler
import (
"log/slog"
"net/http"
)
func notFound(slug string, err error, w http.ResponseWriter, r *http.Request) {
respondWithError(slug, err, w, r, http.StatusNotFound)
}
func badRequest(slug string, err error, w http.ResponseWriter, r *http.Request) {
respondWithError(slug, err, w, r, http.StatusInternalServerError)
}
func internal(slug string, err error, w http.ResponseWriter, r *http.Request) {
respondWithError(slug, err, w, r, http.StatusInternalServerError)
}
func respondWithError(slug string, err error, w http.ResponseWriter, r *http.Request, status int) {
slog.Error("http error occured", "slug", slug, "error", err, "path", r.URL.Path)
http.Error(w, slug, status)
}