portfolio/api/handlers/errorHandlers.go
Darius klein 45ccb19245
Some checks failed
build and deploy portfolio / build (pull_request) Successful in 48s
build and deploy portfolio / publish-docs (pull_request) Successful in 4s
build and deploy portfolio / publish-portfolio (pull_request) Failing after 3s
login refactor
2025-05-09 21:31:48 +02:00

40 lines
955 B
Go

package handlers
import (
"log"
"net/http"
)
func InternalServerErrorHandler(w http.ResponseWriter, err error) {
setError(w, http.StatusInternalServerError, err.Error())
}
func NotFoundHandler(w http.ResponseWriter) {
setError(w, http.StatusNotFound, "404 Not Found")
}
func BadRequestHandler(w http.ResponseWriter) {
setError(w, http.StatusBadRequest, "404 Not Found")
}
func UnprocessableEntityHandler(w http.ResponseWriter, err error) {
setError(w, http.StatusUnprocessableEntity, err.Error())
}
func UnauthorizedHandler(w http.ResponseWriter) {
log.Println("unauthorized")
setError(w, http.StatusUnauthorized, "Unauthorized")
}
func NotImplementedHandler(w http.ResponseWriter) {
setError(w, http.StatusNotImplemented, "WORK IN PROGRESS")
}
func setError(w http.ResponseWriter, httpStatus int, errorMessage string) {
w.WriteHeader(httpStatus)
if _, err := w.Write([]byte(errorMessage)); err != nil {
log.Println(err)
}
return
}