diff --git a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java index c4c2c7a..7fe36d3 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java @@ -47,12 +47,17 @@ public class UserController { @PutMapping("/updateinfo") public ResponseEntity updateUserInfo(@RequestBody InfoDto infoDto, HttpServletRequest request) { - String token = request.getHeader("Authorization"); - Long userId = Long.parseLong(jwtUtil.getUserId(token)); - userService.changeUserInfo(infoDto, userId); + try { + String token = request.getHeader("Authorization"); + Long userId = Long.parseLong(jwtUtil.getUserId(token)); + + userService.changeUserInfo(infoDto, userId); + return ResponseEntity.ok("Password changed successfully"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body(e.getMessage()); + } - return new ResponseEntity<>(HttpStatus.OK); } // 비밀번호 변경 diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java index 9b71b61..310a2e6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java @@ -72,11 +72,11 @@ public class UserServiceImpl implements UserService { @Override public void changeUserInfo(InfoDto infoDto, Long id) { - User user = userRepository.findById(id).orElseThrow(IllegalArgumentException::new); + User user = userRepository.findById(id).orElse(null); if (isEmailExist(infoDto.getEmail())) { - throw new IllegalArgumentException("이미 사용 중인 이메일입니다."); + throw new RuntimeException("이미 사용 중인 이메일입니다."); }