mirror of
https://github.com/skidoodle/pastebin
synced 2025-10-14 09:44:48 +02:00
v2
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user