{"record":{"id":"348bbedb9941c4a4","repo":"karatelabs/karate","slug":"expected-status-actual","errorCode":null,"errorMessage":"expected status: , actual: ","messagePattern":"expected status: , actual: ","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/StepExecutor.java","lineNumber":2407,"sourceCode":"                }\n                return response;\n            } else {\n                logger.debug(\"retry condition not satisfied: {}\", retryUntil);\n            }\n\n            // Restore request state for next retry (http().invoke() resets it)\n            http().restoreFrom(httpCopy);\n\n            retryCount++;\n        }\n    }\n\n    private void executeStatus(Step step) {\n        int expected = Integer.parseInt(step.getText().trim());\n        Object statusObj = runtime.getVariable(\"responseStatus\");\n        int actual = statusObj instanceof Number n ? n.intValue() : Integer.parseInt(statusObj.toString());\n        if (actual != expected) {\n            throw new AssertionError(\"expected status: \" + expected + \", actual: \" + actual);\n        }\n    }\n\n    /**\n     * Handles: multipart file myFile = { read: 'file.txt', filename: 'test.txt', contentType: 'text/plain' }\n     * Or shorthand: multipart file myFile = read('file.txt')\n     */\n    @SuppressWarnings(\"unchecked\")\n    private void executeMultipartFile(Step step) {\n        String text = step.getText();\n        int eqIndex = StepUtils.findAssignmentOperator(text);\n        if (eqIndex < 0) {\n            throw new RuntimeException(\"multipart file requires '=' assignment: \" + text);\n        }\n        String name = text.substring(0, eqIndex).trim();\n        String expr = text.substring(eqIndex + 1).trim();\n\n        Object value = evalKarateExpression(expr);","sourceCodeStart":2389,"sourceCodeEnd":2425,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/StepExecutor.java#L2389-L2425","documentation":"The `status <code>` step asserts that the last HTTP response's status equals the expected integer. When the actual `responseStatus` variable differs, StepExecutor throws an AssertionError showing both values, failing the scenario's HTTP assertion.","triggerScenarios":"A `status 200` (or similar) step ran after an HTTP call whose actual response status differed, e.g. server returned 404, 500, 401.","commonSituations":"Endpoint changed or route misspelled (404); authentication missing/expired (401); server-side bug (500); asserting 200 when an API intentionally returns 201/204; environment pointing at the wrong service.","solutions":["Compare expected vs actual in the message; if the actual is correct, update the step (e.g. `status 201`).","Inspect `response` in the report to understand why the server returned that status.","Fix auth, URL, or payload issues causing the non-success status.","Use `status [200, 204]`-style matching or soft assertions if multiple statuses are acceptable."],"exampleFix":"// before\nAnd status 200\n// after (endpoint legitimately returns 201 on create)\nAnd status 201","handlingStrategy":"validation","validationCode":"// Assert status manually first to get a richer failure message\nAnd def actualStatus = responseStatus\n* if (actualStatus != 200) karate.log('unexpected status ' + actualStatus + ' body: ' + response)\nAnd status 200","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the API contract: use the status code the endpoint actually returns (201/204 etc.).","Inspect `response` and `responseStatus` in the report when a status assertion fails.","Keep feature files in sync with API spec changes.","Use soft/multi-status matching when a range of statuses is valid."],"tags":["karate","http","assertion","status-code"],"backgroundTag":"unexpected-http-status","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}