Skip to content

Commit

Permalink
feat: userId 없을 때 에러처리
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuChaeHyun committed Nov 4, 2023
1 parent 54289dd commit 7083d57
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
Binary file modified build/libs/UserService-0.0.1-SNAPSHOT.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions build/tmp/bootJar/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.example.UserService.UserServiceApplication
Spring-Boot-Version: 3.1.3
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
Build-Jdk-Spec: 17
Implementation-Title: UserService
Implementation-Version: 0.0.1-SNAPSHOT

Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.example.UserService.dto.EmailVerificationResult;
import com.example.UserService.dto.JWTAuthResponse;
import com.example.UserService.dto.UserResponse;
import com.example.UserService.exception.BusinessLogicException;
import com.example.UserService.exception.ExceptionCode;
import com.example.UserService.service.UserService;
import com.example.UserService.vo.RequestLogin;
import com.example.UserService.vo.RequestUser;
Expand Down Expand Up @@ -49,8 +51,15 @@ public ResponseEntity<String> register(@RequestBody RequestUser requestUser){

@GetMapping("/response_userById/{userId}")
public ResponseEntity<UserResponse> findUserResponseByUserId(@PathVariable("userId") Long userId) {
UserResponse userResponse = userService.getUserResponseByUserId(userId);
return ResponseEntity.ok().body(userResponse);
try {
UserResponse userResponse = userService.getUserResponseByUserId(userId);
return ResponseEntity.ok().body(userResponse);
} catch (BusinessLogicException e) {
ExceptionCode exceptionCode = e.getExceptionCode();
int status = exceptionCode.getStatus();
String message = exceptionCode.getMessage();
return ResponseEntity.status(status).body(new UserResponse(message));
}
}

@GetMapping("/response_userByEmail/{email}")
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/example/UserService/dto/UserResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import lombok.Getter;

//feignClient 응답용

@Getter
public class UserResponse {
private Long id;
private String email;
private String name;
private String phoneNumber;
private boolean isApproved;
private String message;

public UserResponse(Long id, String email, String name, String phoneNumber, boolean isApproved) {
this.id = id;
Expand All @@ -18,4 +20,8 @@ public UserResponse(Long id, String email, String name, String phoneNumber, bool
this.phoneNumber = phoneNumber;
this.isApproved = isApproved;
}

public UserResponse(String message) {
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ public String register(RequestUser requestUser) {

@Override
public UserResponse getUserResponseByUserId(Long userId) {
return userRepository.findUserResponseByUserId(userId);
UserResponse userResponse = userRepository.findUserResponseByUserId(userId);

if (userResponse == null) {
throw new BusinessLogicException(ExceptionCode.MEMBER_NOT_FOUND);
}

return userResponse;
}

@Override
Expand Down

0 comments on commit 7083d57

Please sign in to comment.