{"record":{"id":"e56be1caafc43c6e","repo":"juspay/hyperswitch","slug":"user-login-call-failed-to-fetch-user-info-with-sta","errorCode":null,"errorMessage":"User login call failed to fetch user info with status: \"${response.status}\" and message: \"${response.body.error.message}\"","messagePattern":"User login call failed to fetch user info with status: \"(.+?)\" and message: \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cypress-tests/cypress/support/commands.js","lineNumber":6957,"sourceCode":"  }).then((response) => {\n    logRequestId(response.headers[\"x-request-id\"]);\n\n    cy.wrap(response).then(() => {\n      if (response.status === 200) {\n        expect(response.body, \"merchant_id\").to.have.property(\"merchant_id\").and\n          .to.not.be.empty;\n        expect(response.body, \"organization_id\").to.have.property(\"org_id\").and\n          .to.not.be.empty;\n        expect(response.body, \"profile_id\").to.have.property(\"profile_id\").and\n          .to.not.be.empty;\n\n        globalState.set(\"merchantId\", response.body.merchant_id);\n        globalState.set(\"organizationId\", response.body.org_id);\n        globalState.set(\"profileId\", response.body.profile_id);\n\n        globalState.set(\"userInfoToken\", userInfoToken);\n      } else {\n        throw new Error(\n          `User login call failed to fetch user info with status: \"${response.status}\" and message: \"${response.body.error.message}\"`\n        );\n      }\n    });\n  });\n});\n\n// Specific to routing tests\nCypress.Commands.add(\"ListMcaByMid\", (globalState) => {\n  const merchantId = globalState.get(\"merchantId\");\n  cy.request({\n    method: \"GET\",\n    url: `${globalState.get(\"baseUrl\")}/account/${merchantId}/connectors`,\n    headers: {\n      \"Content-Type\": \"application/json\",\n      \"api-key\": globalState.get(\"apiKey\"),\n      \"X-Merchant-Id\": merchantId,\n    },","sourceCodeStart":6939,"sourceCodeEnd":6975,"githubUrl":"https://github.com/juspay/hyperswitch/blob/9b8b89dc378b62c9a6feda647bad4719d2de7699/cypress-tests/cypress/support/commands.js#L6939-L6975","documentation":"Thrown by userInfo when GET /user (Authorization: Bearer {userInfoToken}) responds non-200. The user_info token is short-lived, so 401 expiry is the most common cause; 403/404 typically indicate the token lacks scope or the user record is gone.","triggerScenarios":"Long gap between terminate2Fa and userInfo so the bearer token expired (401); token invalid because terminate2Fa actually failed; user deleted or permissions changed mid-run; wrong baseUrl hitting another environment.","commonSituations":"Slow CI or many setup steps between login and /user call; reusing a recorded token across retries; environment mismatch (local token against staging).","solutions":["Re-run the whole login chain (userLogin → terminate2Fa → userInfo) immediately before any step that needs merchantId/profileId","Confirm terminate2Fa succeeded and set userInfoToken (see error 69)","Check x-request-id in server logs to distinguish expiry (401) from authorization (403)","Verify globalState baseUrl matches the environment the user belongs to"],"exampleFix":"// before (stale token reused)\ncy.userInfo(globalState);\n// after\ncy.userLogin(globalState);\ncy.terminate2Fa(globalState);\ncy.userInfo(globalState);","handlingStrategy":"retry","validationCode":"// refresh the user_info token if it may be stale\nconst issuedAt = globalState.get('userInfoTokenIssuedAt');\nif (!globalState.get('userInfoToken') || isOlderThanMinutes(issuedAt, 10)) {\n  cy.userLogin(globalState);\n  cy.terminate2Fa(globalState);\n}\ncy.userInfo(globalState);","typeGuard":null,"tryCatchPattern":"cy.wrap(null)\n  .then(() => cy.userInfo(globalState))\n  .catch((e) => {\n    if (/fetch user info with status: \"401\"/.test(e.message)) {\n      // token expired mid-run: re-authenticate once and retry\n      cy.userLogin(globalState);\n      cy.terminate2Fa(globalState);\n      return cy.userInfo(globalState);\n    }\n    throw e;\n  });","preventionTips":["Do the login chain as late as possible, right before the first use of merchantId/profileId","Re-authenticate in a beforeEach for long specs instead of once in a before","Distinguish 401 (expired token) from 403 (permissions) in the catch so retries do not mask real issues"],"tags":["cypress","auth","token-expiry","user-api","http-error"],"backgroundTag":null,"analyzedSha":"9b8b89dc378b62c9a6feda647bad4719d2de7699","analyzedAt":"2026-08-16T09:01:53.433Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}