{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/client-side-encryption/providers/azure.ts#L79-L115","documentation":"Thrown when expires_in is present but cannot be converted to a finite number (Number('abc')*1000 yields NaN). The driver multiplies expires_in by 1000 to get milliseconds; a non-numeric value means the token expiry cannot be computed, so caching would be unsafe. Note: the code checks Number.isNaN after multiplication, so non-finite strings ('Infinity') and unparseable values are caught, though a numeric string like '3600' works.","triggerScenarios":"In parseResponse() when Number(body.expires_in) * 1000 is NaN; reachable via a mock/custom token endpoint returning a non-numeric expires_in.","commonSituations":"Mock server returning expires_in as an object or arbitrary string; a token service returning a date string instead of a seconds count; proxy mangling the field.","solutions":["Ensure expires_in is a numeric value (seconds) in the token response.","If mocking the endpoint, return expires_in: 3600 not '1h' or an ISO date.","Avoid pointing AzureKMSRequestOptions.url at non-conformant token services."],"exampleFix":"// before: { \"access_token\": \"t\", \"expires_in\": \"1h\" }\n// after:  { \"access_token\": \"t\", \"expires_in\": 3600 }","handlingStrategy":"validation","validationCode":"// Validate a numeric expires_in when mocking.\nfunction validExpiresIn(v: unknown): v is number {\n  return typeof v === 'number' && Number.isFinite(v) || (typeof v === 'string' && Number.isFinite(Number(v)));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Return expires_in as a number of seconds in mocks.","Avoid date strings or duration strings like '1h'."],"tags":["csfle","azure-kms","queryable-encryption"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}