{"record":{"id":"c6535a1785818bab","repo":"yudaocode/SpringBoot-Labs","slug":"error-c6535a","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":46,"sourceCode":"            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\n    @PostMapping(\"/user/update\")\n    public Boolean update(@RequestBody UserUpdateVO updateVO) {\n        logger.info(\"[update][收到更新请求：{}]\", updateVO.toString());\n        return true;\n    }\n\n}\n","sourceCodeStart":28,"sourceCodeEnd":56,"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#L28-L56","documentation":"Intentional demo exception in lab-71's UserController. getCurrentUser compares the Authorization header against the hard-coded token 'token001' issued by the login endpoint; any non-matching value throws a RuntimeException (HTTP 500 by default). Missing header never reaches this line — Spring rejects it with 400 because @RequestHeader is required.","triggerScenarios":"GET /user/get-current with an Authorization header whose value is not exactly 'token001' — e.g. a stale token, a typo, or a Bearer-prefixed value ('Bearer token001') which fails the strict equals.","commonSituations":"Calling get-current before login so no token is known; copying the token with extra whitespace or a 'Bearer ' prefix because real JWT flows use that format; restarting/resetting the demo and using an old token.","solutions":["POST /user/login with the demo credentials first and use the returned token verbatim in the Authorization header.","If your client adds 'Bearer ', strip it or change the comparison to authorization.replace(\"Bearer \", \"\").","Return 401 instead of a bare RuntimeException via @ControllerAdvice or ResponseStatusException."],"exampleFix":"// before\nif (\"token001\".equals(authorization)) { ... }\nthrow new RuntimeException(\"小朋友，你没有登录哟！\");\n\n// after — accept both raw and Bearer-prefixed tokens, correct status\nString token = authorization.startsWith(\"Bearer \") ? authorization.substring(7) : authorization;\nif (\"token001\".equals(token)) { ... }\nthrow new ResponseStatusException(HttpStatus.UNAUTHORIZED, \"未登录\");","handlingStrategy":"validation","validationCode":"// Obtain and normalize the token before calling\nString token = loginAndGetToken(); // returns \"token001\" in this demo\nif (token == null || token.isEmpty()) throw new IllegalStateException(\"not logged in\");\nString auth = token.startsWith(\"Bearer \") ? token : token; // demo expects raw value","typeGuard":null,"tryCatchPattern":"try {\n    return restTemplate.getForObject(url + \"/user/get-current?full=true\", Map.class,\n            Collections.singletonMap(\"Authorization\", \"token001\"));\n} catch (HttpStatusCodeException e) {\n    if (e.getStatusCode().is5xxServerError() && e.getResponseBodyAsString().contains(\"没有登录\")) {\n        // re-login and retry once\n    }\n    throw e;\n}","preventionTips":["Always login first and reuse the returned token verbatim.","Don't prefix the token with 'Bearer ' unless the server strips it.","Handle 401/refresh in real clients instead of retrying blindly."],"tags":["spring-boot","tutorial-demo","authentication","http-client"],"backgroundTag":null,"analyzedSha":"6c12efaed06d12907a0f40dd2ad1f7020aec8798","analyzedAt":"2026-08-14T13:06:31.500Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}