juspay/hyperswitch · error · Error

Invalid requestType: ${requestType}

Error message

Invalid requestType: ${requestType}

What it means

Thrown synchronously by setConfigs when requestType is present but not a key of REQUEST_CONFIG — only CREATE, UPDATE, FETCH, DELETE (uppercase) are accepted. The lookup REQUEST_CONFIG[requestType] returns undefined for anything else, including lowercase or misspelled variants.

Source

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

    }
  }
);

Cypress.Commands.add("setConfigs", (globalState, key, value, requestType) => {
  if (!key || !requestType) {
    throw new Error("Key and requestType are required parameters");
  }

  const REQUEST_CONFIG = {
    CREATE: { method: "POST", useKey: false },
    UPDATE: { method: "POST", useKey: true },
    FETCH: { method: "GET", useKey: true },
    DELETE: { method: "DELETE", useKey: true },
  };

  const config = REQUEST_CONFIG[requestType];
  if (!config) {
    throw new Error(`Invalid requestType: ${requestType}`);
  }

  const apiKey = globalState.get("adminApiKey");
  const baseUrl = globalState.get("baseUrl");
  const url = `${baseUrl}/configs/${config.useKey ? key : ""}`;

  const getRequestBody = {
    CREATE: () => ({ key, value }),
    UPDATE: () => ({ value }),
  };
  const body = getRequestBody[requestType]?.() || undefined;

  cy.request({
    method: config.method,
    url,
    headers: {
      "Content-Type": "application/json",
      "api-key": apiKey,

View on GitHub (pinned to 9b8b89dc37)

Solutions

  1. Use exactly 'CREATE' | 'UPDATE' | 'FETCH' | 'DELETE' (uppercase) at every call site
  2. Normalize fixture input: requestType = String(raw).toUpperCase() before calling setConfigs
  3. If the admin API gained a new operation, add it to REQUEST_CONFIG plus the method/useKey/body entries

Example fix

// before
cy.setConfigs(globalState, 'ucs_enabled', 'true', 'create');
// after
cy.setConfigs(globalState, 'ucs_enabled', 'true', 'CREATE');
Defensive patterns

Strategy: type-guard

Validate before calling

// normalize before calling
const REQUEST_TYPES = ['CREATE', 'UPDATE', 'FETCH', 'DELETE'];
const normalized = String(rawRequestType ?? '').toUpperCase();
if (!REQUEST_TYPES.includes(normalized)) {
  throw new Error(`requestType must be one of ${REQUEST_TYPES.join('|')}`);
}
cy.setConfigs(globalState, key, value, normalized);

Type guard

const isRequestType = (v) =>
  ['CREATE', 'UPDATE', 'FETCH', 'DELETE'].includes(v);

Prevention

When it happens

Trigger: Passing 'create', 'Delete', 'PATCH', or a typo like 'CREAT' as requestType; interpolating requestType from a fixture whose value was never normalized to the uppercase enum.

Common situations: Fixture-driven request types with inconsistent casing; refactoring from string literals to constants and missing a call site; new operation type added to the API but not to REQUEST_CONFIG.

Related errors


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