{"record":{"id":"b2157e388678a936","repo":"mastra-ai/mastra","slug":"error-message-mastraerror-rethrown-with-mapped-st-b2157e","errorCode":null,"errorMessage":"error.message (MastraError rethrown with mapped status in GET_ITEM_VERSION route)","messagePattern":"error\\.message \\(MastraError rethrown with mapped status in GET_ITEM_VERSION route\\)","errorType":"http","errorClass":"HTTPException","httpStatus":null,"severity":"error","filePath":"packages/server/src/server/handlers/datasets.ts","lineNumber":1171,"sourceCode":"  summary: 'Get item at specific dataset version',\n  description: 'Returns the item as it existed at a specific dataset version',\n  tags: ['Datasets'],\n  requiresAuth: true,\n  handler: async ({ mastra, datasetId, itemId, datasetVersion }) => {\n    assertDatasetsAvailable();\n    try {\n      const ds = await mastra.datasets.get({ id: datasetId });\n      const item = await ds.getItem({ itemId, version: datasetVersion });\n      if (!item) {\n        throw new HTTPException(404, { message: `Item ${itemId} not found at version ${datasetVersion}` });\n      }\n      if ((item as any).datasetId !== datasetId) {\n        throw new HTTPException(404, { message: `Item not found in dataset: ${itemId}` });\n      }\n      return item as any;\n    } catch (error) {\n      if (error instanceof MastraError) {\n        throw new HTTPException(getHttpStatusForMastraError(error.id) as StatusCode, { message: error.message });\n      }\n      return handleError(error, 'Error getting item version');\n    }\n  },\n});\n\n// ============================================================================\n// Batch Operations Routes\n// ============================================================================\n\nexport const BATCH_INSERT_ITEMS_ROUTE = createRoute({\n  method: 'POST',\n  path: '/datasets/:datasetId/items/batch',\n  responseType: 'json',\n  pathParamSchema: datasetIdPathParams,\n  bodySchema: batchInsertItemsBodySchema,\n  responseSchema: batchInsertItemsResponseSchema,\n  summary: 'Batch insert items to dataset',","sourceCodeStart":1153,"sourceCodeEnd":1189,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/datasets.ts#L1153-L1189","documentation":"Fallback branch of the GET_ITEM_VERSION route: any MastraError thrown by mastra.datasets.get or ds.getItem is rethrown as an HTTPException with a status code mapped from the error ID via getHttpStatusForMastraError and the original error.message preserved in the response body.","triggerScenarios":"GET /datasets/:datasetId/items/:itemId/versions/:datasetVersion where the underlying call throws a MastraError — dataset not found, invalid version format handled in storage, storage backend failure.","commonSituations":"Nonexistent datasetId; malformed datasetVersion slipping past path validation into storage; storage adapter connection failures; datasets domain not configured in the deployment.","solutions":["Inspect error.message/HTTP status in the response to identify the mapped MastraError root cause.","Verify the datasetId exists via GET /api/datasets.","Ensure datasetVersion is a valid version number from GET /datasets/:datasetId/versions.","Check storage backend health and configuration."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const dsRes = await fetch(`/api/datasets/${datasetId}`).then(r => r.json());\nif (!dsRes) throw new Error(`Dataset ${datasetId} not found`);\nconst versions = await fetch(`/api/datasets/${datasetId}/versions`).then(r => r.json());\nif (!versions.versions?.some(v => v.version === datasetVersion)) {\n  throw new Error(`Version ${datasetVersion} is not a valid dataset version`);\n}","typeGuard":"function isValidVersion(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 0;\n}","tryCatchPattern":"try {\n  const res = await fetch(`/api/datasets/${datasetId}/items/${itemId}/versions/${version}`);\n  if (!res.ok) {\n    const body = await res.json().catch(() => null);\n    throw new Error(`getItemVersion failed (${res.status}): ${body?.message ?? res.statusText}`);\n  }\n  return await res.json();\n} catch (err) {\n  console.error(err);\n  throw err;\n}","preventionTips":["Validate datasetVersion against GET /datasets/:id/versions before calling.","Confirm the datasetId exists before item-level calls.","Keep storage adapter configuration verified in CI.","Log response status + message to map back to the underlying MastraError quickly."],"tags":["mastra-error","http-mapping","storage","datasets"],"backgroundTag":"storage-backend-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}