{"record":{"id":"77eb5a725faa939c","repo":"karatelabs/karate","slug":"missing-mock-or-handler-in-intercept-config-configmap","errorCode":null,"errorMessage":"missing 'mock' or 'handler' in intercept config: {configMap}","messagePattern":"missing 'mock' or 'handler' in intercept config: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/Driver.java","lineNumber":455,"sourceCode":"                            }\n                            io.karatelabs.http.HttpResponse httpResponse = mockHandler.apply(httpRequest);\n                            if (httpResponse != null) {\n                                Map<String, Object> responseHeaders = new java.util.LinkedHashMap<>();\n                                if (httpResponse.getHeaders() != null) {\n                                    for (Map.Entry<String, List<String>> entry : httpResponse.getHeaders().entrySet()) {\n                                        List<String> values = entry.getValue();\n                                        if (values != null && !values.isEmpty()) {\n                                            responseHeaders.put(entry.getKey(), values.getLast());\n                                        }\n                                    }\n                                }\n                                return InterceptResponse.of(httpResponse.getStatus(), responseHeaders,\n                                        httpResponse.getBodyBytes() != null ? httpResponse.getBodyBytes() : new byte[0]);\n                            }\n                            return null;\n                        });\n                    } else {\n                        throw new RuntimeException(\"missing 'mock' or 'handler' in intercept config: \" + configMap);\n                    }\n                }\n                return null;\n            };\n\n            // Dialog handling\n            case DriverApi.DIALOG -> (JavaCallable) (ctx, args) -> {\n                boolean accept = args.length > 0 && Boolean.TRUE.equals(args[0]);\n                if (args.length > 1 && args[1] != null) {\n                    dialog(accept, String.valueOf(args[1]));\n                } else {\n                    dialog(accept);\n                }\n                return null;\n            };\n            case DriverApi.ON_DIALOG -> (JavaCallable) (ctx, args) -> {\n                if (args.length == 0 || args[0] == null) {\n                    onDialog(null);","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/Driver.java#L437-L473","documentation":"The INTERCEPT callable in Driver.jsGet requires each intercept config to carry either a 'mock' (static response spec) or a 'handler' (function producing the response). When the config map has neither, the driver throws this RuntimeException embedding the config map. It is a config-shape validation so interception never silently no-ops.","triggerScenarios":"driver.intercept({ patterns: [...] }) with neither 'mock' nor 'handler' keys; keys misspelled ('mocks', 'respond'); the mock object built conditionally and ended up null/absent.","commonSituations":"Hand-written intercept configs copied from older examples; dynamically built configs where the mock/handler branch wasn't taken; typos after refactoring from 'mock' to a custom name.","solutions":["Provide a 'mock' for a canned response: { patterns: [...], mock: { status: 200, body: '...' } }","Or provide a 'handler' function that returns the response for dynamic mocking","Verify key spellings ('mock', 'handler', 'patterns') and inspect the echoed config map in the message for what actually arrived"],"exampleFix":"// before\ndriver.intercept({ patterns: ['https://x.com/*'], mocks: myMock });\n// after\ndriver.intercept({ patterns: ['https://x.com/*'], mock: { status: 200, body: 'ok' } });","handlingStrategy":"validation","validationCode":"// JS: if (!cfg.mock && !cfg.handler) throw new Error('intercept needs mock or handler');","typeGuard":"// JS: const hasResponse = cfg.mock != null || typeof cfg.handler === 'function';","tryCatchPattern":"try { driver.intercept(cfg); } catch (RuntimeException e) { if (e.getMessage().contains(\"missing 'mock' or 'handler'\")) { /* fix config */ } else throw e; }","preventionTips":["Pair every patterns array with a mock or handler","Avoid renaming the mock/handler keys in helpers","Read the echoed config map in the message to spot typos"],"tags":["ui","driver","intercept","config-validation"],"backgroundTag":"missing-required-config-field","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"}