This commit is contained in:
2025-10-13 13:41:34 +02:00
parent 90f10143da
commit 4b62a9a64b
23 changed files with 679 additions and 196 deletions

View File

@@ -5,19 +5,23 @@ import (
"net/http"
)
// notFound handles 404 Not Found errors.
func notFound(slug string, err error, w http.ResponseWriter, r *http.Request) {
respondWithError(slug, err, w, r, http.StatusNotFound)
}
// badRequest handles 400 Bad Request errors.
func badRequest(slug string, err error, w http.ResponseWriter, r *http.Request) {
respondWithError(slug, err, w, r, http.StatusInternalServerError)
respondWithError(slug, err, w, r, http.StatusBadRequest)
}
// internal handles 500 Internal Server Error errors.
func internal(slug string, err error, w http.ResponseWriter, r *http.Request) {
respondWithError(slug, err, w, r, http.StatusInternalServerError)
}
// respondWithError logs the error and sends an HTTP error response.
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)
slog.Error("http error occurred", "slug", slug, "error", err, "path", r.URL.Path)
http.Error(w, http.StatusText(status), status)
}