{"record":{"id":"877099c193e77498","repo":"juspay/hyperswitch","slug":"retrieve-payment-call-failed-with-error-code-re","errorCode":null,"errorMessage":"Retrieve Payment Call Failed with error code \"${response.body.error.code}\" error message \"${response.body.error.message}\"","messagePattern":"Retrieve Payment Call Failed with error code \"(.+?)\" error message \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cypress-tests/cypress/support/commands.js","lineNumber":4595,"sourceCode":"                  `${payment_id}_${attempt}` &&\n                response.body.status === \"succeeded\"\n              ) {\n                expect(response.body.attempts[key].status).to.equal(\"charged\");\n              } else if (\n                response.body.attempts[key].attempt_id ===\n                  `${payment_id}_${attempt}` &&\n                response.body.status === \"requires_customer_action\"\n              ) {\n                expect(response.body.attempts[key].status).to.equal(\n                  \"authentication_pending\"\n                );\n              } else {\n                expect(response.body.attempts[key].status).to.equal(\"failure\");\n              }\n            }\n          }\n        } else {\n          throw new Error(\n            `Retrieve Payment Call Failed with error code \"${response.body.error.code}\" error message \"${response.body.error.message}\"`\n          );\n        }\n      });\n    });\n  }\n);\n\nCypress.Commands.add(\n  \"retrievePaymentCallAutoRetryTest\",\n  ({ globalState, attempt = null, expectedIntentStatus }) => {\n    const paymentId = globalState.get(\"paymentID\");\n    const baseUrl = globalState.get(\"baseUrl\");\n    const apiKey = globalState.get(\"apiKey\");\n    const maxRetries = globalState.get(\"max_auto_retries_enabled\");\n\n    // Check if Step-Up retry is enabled from globalState flag\n    const isStepUpRetryEnabled =","sourceCodeStart":4577,"sourceCodeEnd":4613,"githubUrl":"https://github.com/juspay/hyperswitch/blob/9b8b89dc378b62c9a6feda647bad4719d2de7699/cypress-tests/cypress/support/commands.js#L4577-L4613","documentation":"Throw in the Cypress command retrievePaymentCallTest (cypress-tests/cypress/support/commands.js:4595). The command calls GET /payments/{id}?force_sync=true&expand_attempts=true and expects 200; any non-200 status hits this throw, embedding response.body.error.code and response.body.error.message. It means the retrieve call itself failed — bad/expired credentials, unknown payment id, router 5xx, or the payment is in a state the spec did not declare via its fixture data. If the error body has no error object, the message will show 'undefined', which itself hints at an unexpected response shape.","triggerScenarios":"GET /payments/{paymentID} returns non-200: paymentID in globalState is stale/wrong (404), publishable key/admin key invalid (401), force_sync triggers a router/connector error (5xx), or the payment legitimately failed and the spec passed success data.","commonSituations":"Test retries where globalState was reset between the create and retrieve steps; wrong baseUrl or API keys in env config; connector declines surfacing as failed attempts during force_sync; running specs against an environment where the payment was already terminal.","solutions":["Log the x-request-id header and full response.body to identify error.code, then look it up in the Hyperswitch error-code reference.","Verify globalState paymentID and clientSecret were set by the preceding create/confirm step (stale state is the most common cause of 404/401 here).","If the payment is legitimately failed/unexpected-state, pass fixture data for that outcome or assert the error code instead of letting the command throw.","If force_sync intermittently 5xxes, retry the retrieve once — it is a polling-style endpoint."],"exampleFix":"// before\n} else {\n  throw new Error(`Retrieve Payment Call Failed with error code \"${response.body.error.code}\" error message \"${response.body.error.message}\"`);\n}\n\n// after\n} else {\n  throw new Error(`Retrieve Payment Call Failed (status=${response.status}) with error code \"${response.body?.error?.code}\" error message \"${response.body?.error?.message}\" (request_id=${response.headers[\"x-request-id\"]}, payment_id=${paymentId})`);\n}","handlingStrategy":"retry","validationCode":"// pre-flight: ensure state needed for the retrieve exists before calling retrievePaymentCallTest\nconst paymentId = globalState.get(\"paymentID\");\nconst clientSecret = globalState.get(\"clientSecret\");\nif (!paymentId) throw new Error(\"globalState.paymentID missing — run create/confirm before retrieve\");\nif (!clientSecret) throw new Error(\"globalState.clientSecret missing — cannot authorize retrieve\");","typeGuard":"function isPaymentRetrieveSuccess(body) {\n  return body && typeof body === \"object\" && !body.error && typeof body.status === \"string\";\n}\nfunction isApiErrorBody(body) {\n  return body && typeof body === \"object\" && body.error && typeof body.error.code === \"string\";\n}","tryCatchPattern":"// treat retrieve as pollable: one bounded retry on transient 5xx, fail hard otherwise\nconst tryRetrieve = (n) => cy.retrievePaymentCallTest({ globalState, data }).then(() => null).catch((e) => {\n  if (n > 0 && /5\\\\d\\\\d/.test(e.message)) return tryRetrieve(n - 1);\n  throw new Error(`${e.message} (payment_id=${globalState.get(\"paymentID\")}, request_id logged by command)`);\n});\ntryRetrieve(1);","preventionTips":["Always seed globalState (paymentID, clientSecret) in the same test before retrieving; never assume state from a previous spec.","Pass fixture data describing the expected payment state so the command asserts instead of throwing on non-200.","Guard the error template with optional chaining (response.body?.error?.code) so a missing error object does not yield 'undefined'.","Log the x-request-id so the failing retrieve can be traced in server logs."],"tags":["cypress","hyperswitch","payments","retrieve-payment","api-error","test-assertion"],"backgroundTag":null,"analyzedSha":"9b8b89dc378b62c9a6feda647bad4719d2de7699","analyzedAt":"2026-08-16T09:01:53.433Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}