juspay/hyperswitch · error · Error

Invalid capture method ${response.body.capture_method}

Error message

Invalid capture method ${response.body.capture_method}

What it means

Thrown by the confirmCallTest command (cypress-tests/cypress/support/commands.js:3426) when a successful (200) confirm response carries a capture_method outside the modeled set {automatic, manual, manual_multiple}. The command dispatches its assertion tree on capture_method; an unrecognized value (new enum, undefined) falls straight into this throw.

Source

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

                );
                if (
                  response.body.setup_future_usage === "off_session" &&
                  response.body.status === "succeeded" &&
                  globalState.get("connectorId") !== "tsys_transit"
                ) {
                  expect(
                    response.body.connector_mandate_id,
                    "connector_mandate_id"
                  ).to.not.be.null;
                }
              }
            } else {
              throw new Error(
                `Invalid authentication type ${response.body.authentication_type}`
              );
            }
          } else {
            throw new Error(
              `Invalid capture method ${response.body.capture_method}`
            );
          }
        } else {
          defaultErrorHandler(response, resData);
        }
      });
    });
  }
);

Cypress.Commands.add(
  "confirmCallAutoRetryTest",
  (confirmBody, data, confirm, globalState) => {
    const { Request: reqData = {}, Response: resData = {} } = data || {};

    const apiKey = globalState.get("publishableKey");
    const baseUrl = globalState.get("baseUrl");

View on GitHub (pinned to 9b8b89dc37)

Solutions

  1. Log response.body.capture_method to see the exact unrecognized value
  2. Align the request fixture's capture_method with automatic/manual/manual_multiple
  3. If the new enum is legitimate, extend the command's allow-list/branches
  4. Verify the create-intent step actually accepted your capture_method rather than defaulting it

Example fix

// before — chained literals, throws on any new enum
} else if (
  response.body.capture_method === 'manual' ||
  response.body.capture_method === 'manual_multiple'
) { /* ... */ } else {
  throw new Error(`Invalid capture method ${response.body.capture_method}`);
}
// after — single source of truth with a self-describing failure
const CAPTURE_METHODS = ['automatic', 'manual', 'manual_multiple'];
if (CAPTURE_METHODS.includes(response.body.capture_method)) { /* ... */ } else {
  throw new Error(`Invalid capture method '${response.body.capture_method}' (expected one of ${CAPTURE_METHODS.join(', ')})`);
}
Defensive patterns

Strategy: type-guard

Validate before calling

const CAPTURE_METHODS = ['automatic', 'manual', 'manual_multiple'];
if (!CAPTURE_METHODS.includes(capture_method)) {
  throw new Error(`Unsupported capture_method '${capture_method}' — expected ${CAPTURE_METHODS.join('|')}`);
}

Type guard

const isKnownCaptureMethod = (v) =>
  typeof v === 'string' && ['automatic', 'manual', 'manual_multiple'].includes(v);

Prevention

When it happens

Trigger: The API returns a capture_method the command predates (e.g. a scheduled or new auto-variant enum); the field is undefined because the response shape changed; the fixture requested an exotic capture method the confirm tree never modeled.

Common situations: Backend upgrades adding capture_method values without updating the Cypress command; response-schema drift; copy-pasted fixtures carrying unsupported capture methods.

Related errors


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