mastra-ai/mastra · warning · HTTPException
JSON.stringify(errorResponse)
Error message
JSON.stringify(errorResponse)
What it means
validateBody checks that required fields are present in a request body, accumulating per-field messages like '<key> is required'. If any are missing it throws an HTTPException 400 whose message is the JSON.stringify of the error map. The wire message therefore looks like JSON text, not a human sentence.
Source
Thrown at packages/deployer/src/server/handlers/utils.ts:13
import { HTTPException } from 'hono/http-exception';
// Validation helper
export function validateBody(body: Record<string, unknown>) {
const errorResponse = Object.entries(body).reduce<Record<string, string>>((acc, [key, value]) => {
if (!value) {
acc[key] = `${key} is required`;
}
return acc;
}, {});
if (Object.keys(errorResponse).length > 0) {
throw new HTTPException(400, { message: JSON.stringify(errorResponse) });
}
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Parse the 400 message as JSON — each key maps to '<key> is required' — and add the missing fields to the request body.
- Set Content-Type: application/json and send a valid JSON body.
- Update @mastra/client-js / SDK versions so request payloads match the current server API.
Example fix
// before
curl -X POST /api/workflows/runs/restart -d '{}'
// after
curl -X POST /api/workflows/runs/restart -H 'Content-Type: application/json' -d '{"runId":"abc"}' Defensive patterns
Strategy: validation
Validate before calling
const required = ['runId'];
for (const key of required) {
if (body?.[key] == null) throw new Error(`Client bug: '${key}' is required before calling this endpoint`);
} Type guard
function hasRequired<T extends object, K extends readonly (keyof T)[]>(body: object, keys: K): body is T {
return keys.every(k => k in body && body[k] != null);
} Try / catch
try {
await client.restartRun(input);
} catch (e) {
if (e?.status === 400) {
const missing = JSON.parse(e.message); // { field: "field is required" }
console.error('Missing fields:', Object.keys(missing));
}
throw e;
} Prevention
- Parse 400 messages as JSON to see exactly which fields are missing
- Always send Content-Type: application/json with a JSON body
- Keep client SDK versions aligned with the server API schema
When it happens
Trigger: POSTing to a deployer server endpoint with a body missing required keys — e.g. omitting runId or resourceId — triggers this 400 with a JSON-encoded object of missing-field messages.
Common situations: Client SDK version mismatch after API schema changes; sending empty bodies from curl/scripts; forgetting Content-Type: application/json so fields never parse.
Related errors
- Query parameter "status" must be "draft" or "published"
- Agent ID is required
- Query parameters "versionId" and "status" are mutually exclu
- Query parameter "status" must be "draft" or "published"
- bad request: ${responseText}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/33d9e240413e403e.
Report an issue: GitHub.