diff --git a/internal/models/errors.go b/internal/models/errors.go new file mode 100644 index 0000000..1e6c52d --- /dev/null +++ b/internal/models/errors.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "net/http" +) + +type JsonError struct { + Status int `json:"status"` + StatusText string `json:"statusText"` + Message string `json:"message"` + Location string `json:"location"` + Error string `json:"error"` +} + +func WriteHttpJsonError(w http.ResponseWriter, status int, err error, location, message string) { + w.WriteHeader(status) + + json.NewEncoder(w).Encode(JsonError{ + Status: status, + StatusText: http.StatusText(status), + Message: message, + Location: location, + Error: err.Error(), + }) +}