mirror of
https://github.com/kaaninchen/Laterna.git
synced 2026-09-17 19:12:48 +00:00
24 lines
546 B
Go
24 lines
546 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/siestaw/laterna/server/cmd/internal/models"
|
|
)
|
|
|
|
func HTTPErrorHandling(w http.ResponseWriter, r *http.Request, status int, message string) {
|
|
timestamp := time.Now().Format("2006-01-02_15-04-05")
|
|
errResp := models.HTTPError{
|
|
Timestamp: timestamp,
|
|
Status: status,
|
|
Error: http.StatusText(status),
|
|
Message: message,
|
|
Path: r.URL.Path,
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
json.NewEncoder(w).Encode(errResp)
|
|
}
|