{"record":{"id":"700a80e06d42a3ee","repo":"mongodb/node-mongodb-native","slug":"malformed-response-body-unable-to-parse-int-from","errorCode":null,"errorMessage":"Malformed response body - unable to parse int from `expires_in` field.","messagePattern":"Malformed response body - unable to parse int from `expires_in` field\\.","errorType":"exception","errorClass":"MongoCryptAzureKMSRequestError","httpStatus":null,"severity":"error","filePath":"src/client-side-encryption/providers/azure.ts","lineNumber":97,"sourceCode":"  if (status !== 200) {\n    throw new MongoCryptAzureKMSRequestError('Unable to complete request.', body);\n  }\n\n  if (!body.access_token) {\n    throw new MongoCryptAzureKMSRequestError(\n      'Malformed response body - missing field `access_token`.'\n    );\n  }\n\n  if (!body.expires_in) {\n    throw new MongoCryptAzureKMSRequestError(\n      'Malformed response body - missing field `expires_in`.'\n    );\n  }\n\n  const expiresInMS = Number(body.expires_in) * 1000;\n  if (Number.isNaN(expiresInMS)) {\n    throw new MongoCryptAzureKMSRequestError(\n      'Malformed response body - unable to parse int from `expires_in` field.'\n    );\n  }\n\n  return {\n    accessToken: body.access_token,\n    expiresOnTimestamp: Date.now() + expiresInMS\n  };\n}\n\n/**\n * @internal\n *\n * exposed for CSFLE\n * [prose test 18](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#azure-imds-credentials)\n */\nexport interface AzureKMSRequestOptions {\n  headers?: Document;","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/client-side-encryption/providers/azure.ts#L79-L115","documentation":"Raised when the Azure IMDS response has an expires_in field but Number(value) * 1000 yields NaN, i.e. expires_in is non-numeric (e.g. a string like 'never' or null). The driver multiplies expires_in (seconds) by 1000 to compute the cache expiry; a non-numeric value makes caching impossible. MongoCryptAzureKMSRequestError.","triggerScenarios":"expires_in present but as a non-numeric string or an object; a malformed mock IMDS response such as { access_token: 'x', expires_in: 'abc' }.","commonSituations":"Test stub returning the wrong type for expires_in; a custom KMS proxy returning an ISO-8601 duration string instead of seconds; Azure returning an unexpected envelope during a platform incident.","solutions":["Ensure the IMDS (or test mock) returns expires_in as a number of seconds (e.g. 86400).","Do not override the Azure KMS request URL/options in production; the real IMDS endpoint always returns a numeric expires_in.","If genuinely from Azure, retry and escalate to Azure support if it persists."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function assertExpiresInNumeric(body) {\n  if (Number.isNaN(Number(body.expires_in))) {\n    throw new Error('expires_in must be a number of seconds');\n  }\n}","typeGuard":"function isNumericExpiresIn(b: unknown): boolean {\n  return typeof b === 'object' && b !== null && !Number.isNaN(Number((b as any).expires_in));\n}","tryCatchPattern":null,"preventionTips":["Mock IMDS must return expires_in as a number (seconds), not a duration string.","Avoid overriding the Azure KMS request URL in production."],"tags":["csfle","azure","kms","testing"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}