#22119·meshery

[Server] Environment writes return 500 for malformed JSON

Author: maverickaayushCreated Sep 27, 2026Updated Sep 28, 2026

Description

The environment create and update endpoints return HTTP 500 when the request body contains malformed JSON, despite the REST contract classifying an invalid request body as a client error.

Current Behavior

Both POST /api/environments and PUT /api/environments/{id} respond with 500 and meshery-server-1226 for an incomplete JSON body such as {"name":.

Expected Behavior

Malformed JSON supplied by the client should produce HTTP 400 Bad Request, matching the documented invalid-request response.

Steps to Reproduce

  1. Send {"name": as the body to POST /api/environments.
  2. Repeat against PUT /api/environments/{valid-id}.
  3. Observe HTTP 500 from both handlers.

Evidence

$ go test ./server/handlers -run '^TestReproEnvironmentWriteRejectsMalformedJSONAsBadRequest$' -count=1
create: status = 500, want 400 for malformed JSON
update: status = 500, want 400 for malformed JSON
FAIL

Both responses contain unexpected end of JSON input, confirming this is request decoding rather than a server failure.

Root Cause

The JSON-unmarshal branches in SaveEnvironment and UpdateEnvironmentHandler hard-code http.StatusInternalServerError.

Affected Components

  • Meshery Server
  • Environment REST handlers
  • API error/status contract

Validation

Executed on master commit 5b75615243e92b088b4ebf6e7bff82d6f60e5462:

go test ./server/handlers -run '^TestReproEnvironmentWriteRejectsMalformedJSONAsBadRequest$' -count=1

Result: deterministic failure in both subtests; actual 500, expected 400.

Acceptance Criteria

  • Malformed JSON returns HTTP 400 for both create and update.
  • The structured MeshKit error response remains intact.
  • Regression tests cover malformed bodies on both routes.

References