{"record":{"id":"cc8531ad61cb40d0","repo":"juspay/hyperswitch","slug":"user-login-call-failed-to-get-totp-token-with-stat","errorCode":null,"errorMessage":"User login call failed to get totp token with status: \"${response.status}\" and message: \"${response.body.error.message}\"","messagePattern":"User login call failed to get totp token with status: \"(.+?)\" and message: \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cypress-tests/cypress/support/commands.js","lineNumber":6876,"sourceCode":"    body: signinBody,\n    failOnStatusCode: false,\n  }).then((response) => {\n    logRequestId(response.headers[\"x-request-id\"]);\n\n    cy.wrap(response).then(() => {\n      if (response.status === 200) {\n        if (response.body.token_type === \"totp\") {\n          expect(response.body, \"totp_token\").to.have.property(\"token\").and.to\n            .not.be.empty;\n\n          const totpToken = response.body.token;\n          if (!totpToken) {\n            throw new Error(\"No token received from login\");\n          }\n          globalState.set(\"totpToken\", totpToken);\n        }\n      } else {\n        throw new Error(\n          `User login call failed to get totp token with status: \"${response.status}\" and message: \"${response.body.error.message}\"`\n        );\n      }\n    });\n  });\n});\nCypress.Commands.add(\"terminate2Fa\", (globalState) => {\n  // Define the necessary variables and constant\n  const baseUrl = globalState.get(\"baseUrl\");\n  const queryParams = `skip_two_factor_auth=true`;\n  const apiKey = globalState.get(\"totpToken\");\n  const url = `${baseUrl}/user/2fa/terminate?${queryParams}`;\n\n  cy.request({\n    method: \"GET\",\n    url: url,\n    headers: {\n      Authorization: `Bearer ${apiKey}`,","sourceCodeStart":6858,"sourceCodeEnd":6894,"githubUrl":"https://github.com/juspay/hyperswitch/blob/9b8b89dc378b62c9a6feda647bad4719d2de7699/cypress-tests/cypress/support/commands.js#L6858-L6894","documentation":"Thrown by userLogin when POST /user/v2/signin?token_only=true responds with any non-200 status. The message interpolates response.body.error.message, which may be undefined for non-JSON or unexpected error shapes, producing the literal string \"undefined\".","triggerScenarios":"Wrong email/password in globalState (401/400), unknown user in this environment, account locked, malformed body (400), or server error (5xx) from the user service.","commonSituations":"Env vars / CLI args for email and password not passed to the Cypress run; the user only exists in a different environment (local vs staging); password rotated; user already signed in elsewhere causing a conflict.","solutions":["Check the x-request-id logged by logRequestId and look the request up in server logs","Verify the email/password reaching the test (usually env vars or CLI args wired into the before hook that sets globalState)","Confirm the user exists in the target environment and 2FA/TOTP is enabled for the org","Use optional chaining (response.body?.error?.message ?? JSON.stringify(response.body)) so the message never degrades to 'undefined'"],"exampleFix":"// before\n`User login call failed to get totp token with status: \"${response.status}\" and message: \"${response.body.error.message}\"`\n// after\n`User login call failed to get totp token with status: \"${response.status}\" and message: \"${response.body?.error?.message ?? JSON.stringify(response.body)}\"`","handlingStrategy":"try-catch","validationCode":"// fail fast on obviously bad credentials before the call\nconst email = globalState.get('email');\nconst password = globalState.get('password');\nif (!email || !password) {\n  throw new Error('email/password missing — check env vars or CLI args');\n}","typeGuard":null,"tryCatchPattern":"cy.wrap(null).then(() => {\n  try {\n    return cy.userLogin(globalState);\n  } catch (e) {\n    const m = String(e.message);\n    if (m.includes('status: \"401\"')) throw new Error('Bad credentials for signin');\n    if (m.includes('status: \"400\"')) throw new Error('Malformed signin body');\n    throw e;\n  }\n});","preventionTips":["Pass email/password via env/CLI and assert their presence in the before hook","Use a known seeded user per environment and document rotation of its password","Use optional chaining when rendering error messages so 'undefined' never hides the real body"],"tags":["cypress","auth","signin","credentials","http-error"],"backgroundTag":null,"analyzedSha":"9b8b89dc378b62c9a6feda647bad4719d2de7699","analyzedAt":"2026-08-16T09:01:53.433Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}