{"record":{"id":"de893e35b606c663","repo":"yudaocode/SpringBoot-Labs","slug":"error-de893e","errorCode":null,"errorMessage":"小朋友，你的账号密码不正确哟！","messagePattern":"小朋友，你的账号密码不正确哟！","errorType":"http","errorClass":"java.lang.RuntimeException","httpStatus":500,"severity":"warning","filePath":"lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java","lineNumber":30,"sourceCode":" * 用户 Controller\n *\n * 示例代码，纯粹为了演示。\n */\n@RestController\npublic class UserController {\n\n    private final Logger logger = LoggerFactory.getLogger(getClass());\n\n    @PostMapping(\"/user/login\")\n    public Map<String, Object> login(@RequestParam(\"username\") String username,\n                                     @RequestParam(\"password\") String password) {\n        if (\"yudaoyuanma\".equals(username) && \"123456\".equals(password)) {\n            Map<String, Object> tokenMap = new HashMap<>();\n            tokenMap.put(\"userId\", 1);\n            tokenMap.put(\"token\", \"token001\");\n            return tokenMap;\n        }\n        throw new RuntimeException(\"小朋友，你的账号密码不正确哟！\");\n    }\n\n    @GetMapping(\"/user/get-current\")\n    public Map<String, Object> getCurrentUser(@RequestHeader(\"Authorization\") String authorization,\n                                              @RequestParam(\"full\") boolean full) {\n        if (\"token001\".equals(authorization)) {\n            Map<String, Object> userInfo = new HashMap<>();\n            userInfo.put(\"id\", 1);\n            // full 为 true 时，获得完整信息\n            if (full) {\n                userInfo.put(\"nickname\", \"芋道源码\");\n                userInfo.put(\"gender\", 1);\n            }\n            return userInfo;\n        }\n        throw new RuntimeException(\"小朋友，你没有登录哟！\");\n    }\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/yudaocode/SpringBoot-Labs/blob/6c12efaed06d12907a0f40dd2ad1f7020aec8798/lab-71-http-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.java#L12-L48","documentation":"Intentional demo exception in the lab-71 IDEA HTTP Client tutorial. The login endpoint hard-codes a single credential pair (yudaoyuanma/123456); any other combination throws a RuntimeException with this playful message. Since there is no @ExceptionHandler, Spring returns HTTP 500 with the message in the error body.","triggerScenarios":"POST /user/login with any username other than 'yudaoyuanma' or any password other than '123456' (form/RequestParam fields, not JSON body).","commonSituations":"Following the tutorial's .http request files but mistyping the demo credentials; testing what an error response looks like in the IDEA HTTP client (that is the point of the lab); sending credentials as JSON body instead of request parameters so both fields are null/wrong.","solutions":["Send exactly username=yudaoyuanma and password=123456 as request parameters to get the token 'token001'.","If you extended the demo, register the credentials properly instead of relying on the hard-coded pair.","Add a @ControllerAdvice exception handler returning 400/401 instead of an unhandled 500."],"exampleFix":"// before\nthrow new RuntimeException(\"小朋友，你的账号密码不正确哟！\");\n\n// after — proper status code via a handled exception\nthrow new ResponseStatusException(HttpStatus.UNAUTHORIZED, \"账号密码不正确\");","handlingStrategy":"validation","validationCode":"// Validate before calling\nif (!\"yudaoyuanma\".equals(username) || !\"123456\".equals(password)) {\n    // don't call /user/login; show a credential error locally\n}","typeGuard":null,"tryCatchPattern":"// IDEA HTTP client / RestTemplate\ntry {\n    ResponseEntity<Map> resp = restTemplate.postForEntity(url + \"/user/login?username={u}&password={p}\", null, Map.class, user, pass);\n} catch (HttpClientErrorException | HttpServerErrorException e) {\n    // 500 with message body for wrong credentials in this demo\n    log.warn(\"login failed: {}\", e.getResponseBodyAsString());\n}","preventionTips":["Use the exact demo credentials from the tutorial's .http file.","Send credentials as request parameters, not JSON body.","For real apps return 401/400 via exception handlers, never 500 for auth failures."],"tags":["spring-boot","tutorial-demo","authentication","http-client"],"backgroundTag":null,"analyzedSha":"6c12efaed06d12907a0f40dd2ad1f7020aec8798","analyzedAt":"2026-08-14T13:06:31.500Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}