Skip to content

Commit

Permalink
feat(#30): Exception Handling
Browse files Browse the repository at this point in the history
- 임시로 RuntimeException으로 했던 오류를 커스텀 예외로 만들었어요.
  • Loading branch information
cabbage16 committed Nov 27, 2024
1 parent dd4f72b commit c3cdc64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.bamdoliro.sinabro.domain.user.domain.User;
import com.bamdoliro.sinabro.domain.user.domain.Verification;
import com.bamdoliro.sinabro.domain.user.domain.type.Authority;
import com.bamdoliro.sinabro.domain.user.exception.UserAlreadyExistsException;
import com.bamdoliro.sinabro.domain.user.exception.VerifyingHasFailedException;
import com.bamdoliro.sinabro.domain.user.service.VerificationFacade;
import com.bamdoliro.sinabro.infrastructure.persistence.user.UserRepository;
import com.bamdoliro.sinabro.infrastructure.persistence.user.VerificationRepository;
import com.bamdoliro.sinabro.presentation.user.dto.request.SignUpRequest;
Expand All @@ -16,6 +19,7 @@ public class SignUpUseCase {

private final UserRepository userRepository;
private final VerificationRepository verificationRepository;
private final VerificationFacade verificationFacade;

@Transactional
public void execute(SignUpRequest request) {
Expand All @@ -32,15 +36,14 @@ public void execute(SignUpRequest request) {
}

private void validate(SignUpRequest request) {
Verification verification = verificationRepository.findById(request.getEmail())
.orElseThrow(RuntimeException::new);
Verification verification = verificationFacade.getVerification(request.getEmail());

if (!verification.getIsVerified()) {
throw new RuntimeException();
throw new VerifyingHasFailedException();
}

if (userRepository.existsByEmail(request.getEmail())) {
throw new RuntimeException();
throw new UserAlreadyExistsException();
}

verificationRepository.delete(verification);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bamdoliro.sinabro.domain.user.exception;

import com.bamdoliro.sinabro.domain.user.exception.error.UserErrorProperty;
import com.bamdoliro.sinabro.shared.error.SinabroException;

public class UserAlreadyExistsException extends SinabroException {
public UserAlreadyExistsException() {
super(UserErrorProperty.USER_ALREADY_EXISTS);
}
}

0 comments on commit c3cdc64

Please sign in to comment.