{"record":{"id":"f227194e40213458","repo":"juspay/hyperswitch","slug":"blocklist-create-rule-failed-with-status-respon","errorCode":null,"errorMessage":"Blocklist create rule failed with status: ${response.status} and message: ${response.body?.error?.message}","messagePattern":"Blocklist create rule failed with status: (.+?) and message: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cypress-tests/cypress/support/commands.js","lineNumber":7734,"sourceCode":"        \"api-key\": apiKey,\n      },\n      body: body,\n      failOnStatusCode: false,\n    }).then((response) => {\n      logRequestId(response.headers[\"x-request-id\"]);\n\n      cy.wrap(response).then(() => {\n        if (response.status === 200) {\n          expect(response.body)\n            .to.have.property(\"fingerprint_id\")\n            .to.equal(cardBin);\n          expect(response.body)\n            .to.have.property(\"data_kind\")\n            .to.equal(\"card_bin\");\n          expect(response.body).to.have.property(\"created_at\").to.not.be.null;\n          globalState.set(\"blocklistRuleId\", response.body.fingerprint_id);\n        } else {\n          throw new Error(\n            `Blocklist create rule failed with status: ${response.status} and message: ${response.body?.error?.message}`\n          );\n        }\n      });\n    });\n  }\n);\n\nCypress.Commands.add(\"blocklistDeleteRule\", (type, data, globalState) => {\n  const apiKey = globalState.get(\"apiKey\");\n  const baseUrl = globalState.get(\"baseUrl\");\n  const url = `${baseUrl}/blocklist`;\n\n  const body = {\n    type: type,\n    data: data,\n  };\n","sourceCodeStart":7716,"sourceCodeEnd":7752,"githubUrl":"https://github.com/juspay/hyperswitch/blob/9b8b89dc378b62c9a6feda647bad4719d2de7699/cypress-tests/cypress/support/commands.js#L7716-L7752","documentation":"Thrown by blocklistCreateRule when POST /blocklist (api-key auth, body type='card_bin', data=cardBin) responds non-200. On success the command asserts fingerprint_id === cardBin, data_kind === 'card_bin', and a non-null created_at; any failure status throws with the server's error message.","triggerScenarios":"Re-creating a card_bin rule that already exists (duplicate/conflict); invalid or missing apiKey (401/403); malformed card bin value (400); blocklist feature disabled in the environment (404/501).","commonSituations":"Rerunning specs without cleanup, leaving the previous run's rule in place; wrong apiKey in globalState for this environment; feature flag for the blocklist API off in staging.","solutions":["Delete the rule first in a before hook: cy.blocklistDeleteRule('card_bin', cardBin, globalState) — it is idempotent when tolerated","Verify globalState.get('apiKey') is the correct key for the target baseUrl","Check x-request-id in server logs for the exact rejection reason","Confirm the blocklist feature is enabled for the environment"],"exampleFix":"// before\nbefore(() => {\n  cy.blocklistCreateRule(requestBody, cardBin, globalState);\n});\n// after\nbefore(() => {\n  cy.blocklistDeleteRule('card_bin', cardBin, globalState); // clear stale rule\n  cy.blocklistCreateRule(requestBody, cardBin, globalState);\n});","handlingStrategy":"validation","validationCode":"// make creation idempotent: clear any stale rule first\ncy.blocklistDeleteRule('card_bin', cardBin, globalState);\ncy.blocklistCreateRule(requestBody, cardBin, globalState);","typeGuard":null,"tryCatchPattern":"cy.wrap(null)\n  .then(() => cy.blocklistCreateRule(requestBody, cardBin, globalState))\n  .catch((e) => {\n    if (/status: 409/.test(e.message)) {\n      // rule already exists — delete and recreate once\n      cy.blocklistDeleteRule('card_bin', cardBin, globalState);\n      return cy.blocklistCreateRule(requestBody, cardBin, globalState);\n    }\n    throw e;\n  });","preventionTips":["Pair every create with a delete in cleanup hooks so reruns start clean","Validate cardBin format (6-9 digits) before sending","Confirm the apiKey in globalState matches the environment's blocklist-enabled merchant"],"tags":["cypress","blocklist","card-bin","http-error","idempotency"],"backgroundTag":null,"analyzedSha":"9b8b89dc378b62c9a6feda647bad4719d2de7699","analyzedAt":"2026-08-16T09:01:53.433Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}