Files
GoSally/internal/core/utils/http_errors.go
Alexey ec94df5f4a Project structure refactor:
- Change package name general_server to gateway
- Changing the structure of directories and packages
- Adding vendor to the project
2025-07-28 20:16:40 +03:00

23 lines
542 B
Go

package utils
import (
"encoding/json"
"net/http"
)
// writeJSONError writes a JSON error response to the HTTP response writer.
// It sets the Content-Type to application/json, writes the specified HTTP status code
func WriteJSONError(w http.ResponseWriter, status int, msg string) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
resp := map[string]any{
"status": "error",
"error": msg,
"code": status,
}
if err := json.NewEncoder(w).Encode(resp); err != nil {
return err
}
return nil
}