mirror of
https://github.com/Warky-Devs/ResolveSpec.git
synced 2025-05-18 20:57:29 +00:00
Fixed json loading
This commit is contained in:
parent
5f1526b0f4
commit
f3ca6c356a
@ -3,6 +3,7 @@ package resolvespec
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/Warky-Devs/ResolveSpec/pkg/logger"
|
"github.com/Warky-Devs/ResolveSpec/pkg/logger"
|
||||||
@ -25,10 +26,24 @@ func NewAPIHandler(db *gorm.DB) *APIHandler {
|
|||||||
// Main handler method
|
// Main handler method
|
||||||
func (h *APIHandler) Handle(w http.ResponseWriter, r *http.Request, params map[string]string) {
|
func (h *APIHandler) Handle(w http.ResponseWriter, r *http.Request, params map[string]string) {
|
||||||
var req RequestBody
|
var req RequestBody
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
logger.Error("Failed to decode request body: %v", err)
|
if r.Body == nil {
|
||||||
h.sendError(w, http.StatusBadRequest, "invalid_request", "Invalid request body", err)
|
logger.Error("No body to decode")
|
||||||
|
h.sendError(w, http.StatusBadRequest, "invalid_request", "No body to decode", nil)
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
defer r.Body.Close()
|
||||||
|
}
|
||||||
|
if bodyContents, err := io.ReadAll(r.Body); err != nil {
|
||||||
|
logger.Error("Failed to decode read body: %v", err)
|
||||||
|
h.sendError(w, http.StatusBadRequest, "read_request", "Invalid request body", err)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if err := json.Unmarshal(bodyContents, &req); err != nil {
|
||||||
|
logger.Error("Failed to decode request body: %v", err)
|
||||||
|
h.sendError(w, http.StatusBadRequest, "invalid_request", "Invalid request body", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
schema := params["schema"]
|
schema := params["schema"]
|
||||||
|
Loading…
Reference in New Issue
Block a user