{"record":{"id":"33d9e240413e403e","repo":"mastra-ai/mastra","slug":"json-stringify-errorresponse","errorCode":null,"errorMessage":"JSON.stringify(errorResponse)","messagePattern":"JSON\\.stringify\\(errorResponse\\)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"packages/deployer/src/server/handlers/utils.ts","lineNumber":13,"sourceCode":"import { HTTPException } from 'hono/http-exception';\n\n// Validation helper\nexport function validateBody(body: Record<string, unknown>) {\n  const errorResponse = Object.entries(body).reduce<Record<string, string>>((acc, [key, value]) => {\n    if (!value) {\n      acc[key] = `${key} is required`;\n    }\n    return acc;\n  }, {});\n\n  if (Object.keys(errorResponse).length > 0) {\n    throw new HTTPException(400, { message: JSON.stringify(errorResponse) });\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":16,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/deployer/src/server/handlers/utils.ts#L1-L16","documentation":"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.","triggerScenarios":"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.","commonSituations":"Client SDK version mismatch after API schema changes; sending empty bodies from curl/scripts; forgetting Content-Type: application/json so fields never parse.","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."],"exampleFix":"// before\ncurl -X POST /api/workflows/runs/restart -d '{}'\n// after\ncurl -X POST /api/workflows/runs/restart -H 'Content-Type: application/json' -d '{\"runId\":\"abc\"}'","handlingStrategy":"validation","validationCode":"const required = ['runId'];\nfor (const key of required) {\n  if (body?.[key] == null) throw new Error(`Client bug: '${key}' is required before calling this endpoint`);\n}","typeGuard":"function hasRequired<T extends object, K extends readonly (keyof T)[]>(body: object, keys: K): body is T {\n  return keys.every(k => k in body && body[k] != null);\n}","tryCatchPattern":"try {\n  await client.restartRun(input);\n} catch (e) {\n  if (e?.status === 400) {\n    const missing = JSON.parse(e.message); // { field: \"field is required\" }\n    console.error('Missing fields:', Object.keys(missing));\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["server","http","validation","bad-request"],"backgroundTag":"missing-required-request-field","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}