fix: bridge.go — remove encoding/json entirely
Error classification uses string match on unmarshal errors instead of stdlib json.SyntaxError/UnmarshalTypeError type assertions. No exceptions. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
3d3deb1bf5
commit
83bcb1e5e1
1 changed files with 3 additions and 6 deletions
|
|
@ -3,7 +3,6 @@
|
|||
package mcp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
core "dappco.re/go/core"
|
||||
|
|
@ -49,11 +48,9 @@ func BridgeToAPI(svc *Service, bridge *api.ToolBridge) {
|
|||
|
||||
result, err := handler(c.Request.Context(), body)
|
||||
if err != nil {
|
||||
// Classify JSON parse errors as client errors (400),
|
||||
// everything else as server errors (500).
|
||||
var syntaxErr *json.SyntaxError
|
||||
var typeErr *json.UnmarshalTypeError
|
||||
if core.As(err, &syntaxErr) || core.As(err, &typeErr) {
|
||||
// Body present + error = likely bad input (malformed JSON).
|
||||
// No body + error = tool execution failure.
|
||||
if len(body) > 0 && core.Contains(err.Error(), "unmarshal") {
|
||||
c.JSON(http.StatusBadRequest, api.Fail("invalid_input", "Malformed JSON in request body"))
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue