2024-05-16 17:59:21 +02:00
|
|
|
package handlers
|
2024-02-14 00:08:14 +01:00
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
2024-05-19 17:49:20 +02:00
|
|
|
func InternalServerErrorHandler(w http.ResponseWriter, err error) {
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError) //set http status
|
|
|
|
|
_, err = w.Write([]byte(err.Error())) //set response message
|
2024-02-14 00:08:14 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-05-19 17:49:20 +02:00
|
|
|
return
|
2024-02-14 00:08:14 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-13 15:54:09 +01:00
|
|
|
func NotFoundHandler(w http.ResponseWriter) {
|
2024-02-14 00:08:14 +01:00
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
_, err := w.Write([]byte("404 Not Found"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-15 15:21:59 +01:00
|
|
|
|
2024-03-13 15:54:09 +01:00
|
|
|
func BadRequestHandler(w http.ResponseWriter) {
|
2024-02-15 15:21:59 +01:00
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
_, err := w.Write([]byte("400 Bad Request"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-19 17:49:20 +02:00
|
|
|
|
|
|
|
|
func UnprocessableEntityHandler(w http.ResponseWriter, err error) {
|
|
|
|
|
w.WriteHeader(http.StatusUnprocessableEntity) //set http status
|
|
|
|
|
_, err = w.Write([]byte(err.Error())) //set response message
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UnauthorizedHandler(w http.ResponseWriter) {
|
|
|
|
|
w.WriteHeader(http.StatusUnauthorized) //set http status
|
|
|
|
|
_, err := w.Write([]byte("Unauthorized")) //set response message
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-06-24 15:23:38 +02:00
|
|
|
|
|
|
|
|
func NotImplementedHandler(w http.ResponseWriter) {
|
|
|
|
|
w.WriteHeader(http.StatusNotImplemented) //set http status
|
|
|
|
|
_, err := w.Write([]byte("WORK IN PROGRESS"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|