2024-05-16 17:59:21 +02:00
|
|
|
package handlers
|
2024-02-14 00:08:14 +01:00
|
|
|
|
2025-02-24 00:15:10 +01:00
|
|
|
import (
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
2024-02-14 00:08:14 +01:00
|
|
|
|
2024-05-19 17:49:20 +02:00
|
|
|
func InternalServerErrorHandler(w http.ResponseWriter, err error) {
|
2025-02-24 00:15:10 +01:00
|
|
|
setError(w, http.StatusInternalServerError, err.Error())
|
2024-02-14 00:08:14 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-13 15:54:09 +01:00
|
|
|
func NotFoundHandler(w http.ResponseWriter) {
|
2025-02-24 00:15:10 +01:00
|
|
|
setError(w, http.StatusNotFound, "404 Not Found")
|
2024-02-14 00:08:14 +01:00
|
|
|
}
|
2024-02-15 15:21:59 +01:00
|
|
|
|
2024-03-13 15:54:09 +01:00
|
|
|
func BadRequestHandler(w http.ResponseWriter) {
|
2025-02-24 00:15:10 +01:00
|
|
|
setError(w, http.StatusBadRequest, "404 Not Found")
|
2024-02-15 15:21:59 +01:00
|
|
|
}
|
2024-05-19 17:49:20 +02:00
|
|
|
|
|
|
|
|
func UnprocessableEntityHandler(w http.ResponseWriter, err error) {
|
2025-02-24 00:15:10 +01:00
|
|
|
setError(w, http.StatusUnprocessableEntity, err.Error())
|
2024-05-19 17:49:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UnauthorizedHandler(w http.ResponseWriter) {
|
2025-02-24 00:15:10 +01:00
|
|
|
setError(w, http.StatusUnauthorized, "Unauthorized")
|
2024-05-19 17:49:20 +02:00
|
|
|
}
|
2024-06-24 15:23:38 +02:00
|
|
|
|
|
|
|
|
func NotImplementedHandler(w http.ResponseWriter) {
|
2025-02-24 00:15:10 +01:00
|
|
|
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)
|
2024-06-24 15:23:38 +02:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|