juspay/hyperswitch · error · Error

User login call failed to get totp token with status: "${res

Error message

User login call failed to get totp token with status: "${response.status}" and message: "${response.body.error.message}"

What it means

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".

Source

Thrown at cypress-tests/cypress/support/commands.js:6876

    body: signinBody,
    failOnStatusCode: false,
  }).then((response) => {
    logRequestId(response.headers["x-request-id"]);

    cy.wrap(response).then(() => {
      if (response.status === 200) {
        if (response.body.token_type === "totp") {
          expect(response.body, "totp_token").to.have.property("token").and.to
            .not.be.empty;

          const totpToken = response.body.token;
          if (!totpToken) {
            throw new Error("No token received from login");
          }
          globalState.set("totpToken", totpToken);
        }
      } else {
        throw new Error(
          `User login call failed to get totp token with status: "${response.status}" and message: "${response.body.error.message}"`
        );
      }
    });
  });
});
Cypress.Commands.add("terminate2Fa", (globalState) => {
  // Define the necessary variables and constant
  const baseUrl = globalState.get("baseUrl");
  const queryParams = `skip_two_factor_auth=true`;
  const apiKey = globalState.get("totpToken");
  const url = `${baseUrl}/user/2fa/terminate?${queryParams}`;

  cy.request({
    method: "GET",
    url: url,
    headers: {
      Authorization: `Bearer ${apiKey}`,

View on GitHub (pinned to 9b8b89dc37)

Solutions

  1. Check the x-request-id logged by logRequestId and look the request up in server logs
  2. Verify the email/password reaching the test (usually env vars or CLI args wired into the before hook that sets globalState)
  3. Confirm the user exists in the target environment and 2FA/TOTP is enabled for the org
  4. Use optional chaining (response.body?.error?.message ?? JSON.stringify(response.body)) so the message never degrades to 'undefined'

Example fix

// before
`User login call failed to get totp token with status: "${response.status}" and message: "${response.body.error.message}"`
// after
`User login call failed to get totp token with status: "${response.status}" and message: "${response.body?.error?.message ?? JSON.stringify(response.body)}"`
Defensive patterns

Strategy: try-catch

Validate before calling

// fail fast on obviously bad credentials before the call
const email = globalState.get('email');
const password = globalState.get('password');
if (!email || !password) {
  throw new Error('email/password missing — check env vars or CLI args');
}

Try / catch

cy.wrap(null).then(() => {
  try {
    return cy.userLogin(globalState);
  } catch (e) {
    const m = String(e.message);
    if (m.includes('status: "401"')) throw new Error('Bad credentials for signin');
    if (m.includes('status: "400"')) throw new Error('Malformed signin body');
    throw e;
  }
});

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of juspay/hyperswitch@9b8b89dc37 (2026-08-16). Data as JSON: /api/errors/cc8531ad61cb40d0. Report an issue: GitHub.