Files
rcond/pkg/http/handle_error.go
2025-05-17 20:32:53 +02:00

17 lines
315 B
Go

package http
import (
"encoding/json"
"net/http"
)
type ErrorResponse struct {
Error string `json:"error"`
}
func WriteError(w http.ResponseWriter, message string, code int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
json.NewEncoder(w).Encode(ErrorResponse{Error: message})
}