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