{"record":{"id":"eb50d5a636804e79","repo":"xkcoding/spring-boot-demo","slug":"500","errorCode":"500","errorMessage":"服务器出错啦","messagePattern":"服务器出错啦","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"info","filePath":"demo-exception-handler/src/main/java/com/xkcoding/exception/handler/controller/TestController.java","lineNumber":26,"sourceCode":"import org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.ResponseBody;\nimport org.springframework.web.servlet.ModelAndView;\n\n/**\n * <p>\n * 测试Controller\n * </p>\n *\n * @author yangkai.shen\n * @date Created in 2018-10-02 20:49\n */\n@Controller\npublic class TestController {\n\n    @GetMapping(\"/json\")\n    @ResponseBody\n    public ApiResponse jsonException() {\n        throw new JsonException(Status.UNKNOWN_ERROR);\n    }\n\n    @GetMapping(\"/page\")\n    public ModelAndView pageException() {\n        throw new PageException(Status.UNKNOWN_ERROR);\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":34,"githubUrl":"https://github.com/xkcoding/spring-boot-demo/blob/87a142f9604c1a5365b4d24d22c2c11c26a9d5ab/demo-exception-handler/src/main/java/com/xkcoding/exception/handler/controller/TestController.java#L8-L34","documentation":"This is a demo/test endpoint (GET /json) that unconditionally throws a JsonException wrapping Status.UNKNOWN_ERROR (code 500, message '服务器出错啦'). It exists solely to demonstrate the global exception handler's JSON-response path. It will always fire when the endpoint is hit — it is not a runtime failure but a deliberate test throw.","triggerScenarios":"Sending a GET request to /json. The method body contains no conditional logic — it always throws. The JsonException is caught by a @ControllerAdvice handler (if configured) and returned as a JSON ApiResponse with code 500.","commonSituations":"Hitting the demo endpoint during local testing; integration tests that exercise the exception-handler flow; accidental exposure of the test controller in a non-demo deployment.","solutions":["This is expected behavior for the demo — no fix needed unless the endpoint is unwanted.","If this appears in production logs, exclude or remove the TestController bean from production builds.","Verify a @ControllerAdvice with an @ExceptionHandler(JsonException.class) is registered to produce the expected JSON response."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In a @ControllerAdvice handler\n@ExceptionHandler(JsonException.class)\n@ResponseBody\npublic ApiResponse handleJsonException(JsonException e) {\n    log.warn(\"JsonException caught: code={}, msg={}\", e.getCode(), e.getMessage());\n    return ApiResponse.ofMessage(e.getCode(), e.getMessage());\n}","preventionTips":["Register a global @ControllerAdvice with an @ExceptionHandler for JsonException.","Exclude TestController from production profiles using @Profile(\"dev\").","Do not expose demo endpoints in production deployments."],"tags":["spring-boot","exception-handler","demo","test-controller","http-500"],"backgroundTag":null,"analyzedSha":"87a142f9604c1a5365b4d24d22c2c11c26a9d5ab","analyzedAt":"2026-08-14T01:16:58.217Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}