1919import flipnote .user .auth .presentation .dto .response .TokenValidateResponse ;
2020import flipnote .user .auth .presentation .dto .response .UserResponse ;
2121import flipnote .user .global .config .ClientProperties ;
22- import flipnote .user .global .exception .UserException ;
22+ import flipnote .user .global .exception .BizException ;
2323import flipnote .user .user .domain .OAuthLink ;
2424import flipnote .user .user .domain .OAuthLinkRepository ;
2525import flipnote .user .user .domain .User ;
@@ -54,11 +54,11 @@ public class AuthService {
5454 @ Transactional
5555 public UserResponse register (SignupRequest request ) {
5656 if (!emailVerificationRepository .isVerified (request .getEmail ())) {
57- throw new UserException (AuthErrorCode .UNVERIFIED_EMAIL );
57+ throw new BizException (AuthErrorCode .UNVERIFIED_EMAIL );
5858 }
5959
6060 if (userRepository .existsByEmail (request .getEmail ())) {
61- throw new UserException (AuthErrorCode .EMAIL_ALREADY_EXISTS );
61+ throw new BizException (AuthErrorCode .EMAIL_ALREADY_EXISTS );
6262 }
6363
6464 User user = User .builder ()
@@ -76,10 +76,10 @@ public UserResponse register(SignupRequest request) {
7676
7777 public TokenPair login (LoginRequest request ) {
7878 User user = userRepository .findByEmailAndStatus (request .getEmail (), User .Status .ACTIVE )
79- .orElseThrow (() -> new UserException (AuthErrorCode .INVALID_CREDENTIALS ));
79+ .orElseThrow (() -> new BizException (AuthErrorCode .INVALID_CREDENTIALS ));
8080
8181 if (!passwordEncoder .matches (request .getPassword (), user .getPassword ())) {
82- throw new UserException (AuthErrorCode .INVALID_CREDENTIALS );
82+ throw new BizException (AuthErrorCode .INVALID_CREDENTIALS );
8383 }
8484
8585 return jwtProvider .generateTokenPair (user );
@@ -96,18 +96,18 @@ public void logout(String refreshToken) {
9696
9797 public TokenPair refreshToken (String refreshToken ) {
9898 if (refreshToken == null || !jwtProvider .isTokenValid (refreshToken )) {
99- throw new UserException (AuthErrorCode .INVALID_TOKEN );
99+ throw new BizException (AuthErrorCode .INVALID_TOKEN );
100100 }
101101
102102 if (tokenBlacklistRepository .isBlacklisted (refreshToken )) {
103- throw new UserException (AuthErrorCode .BLACKLISTED_TOKEN );
103+ throw new BizException (AuthErrorCode .BLACKLISTED_TOKEN );
104104 }
105105
106106 TokenClaims claims = jwtProvider .extractClaims (refreshToken );
107107
108108 sessionInvalidationRepository .getInvalidatedAtMillis (claims .userId ()).ifPresent (invalidatedAtMillis -> {
109109 if (jwtProvider .getIssuedAt (refreshToken ).getTime () < invalidatedAtMillis ) {
110- throw new UserException (AuthErrorCode .INVALIDATED_SESSION );
110+ throw new BizException (AuthErrorCode .INVALIDATED_SESSION );
111111 }
112112 });
113113
@@ -126,7 +126,7 @@ public void changePassword(Long userId, ChangePasswordRequest request) {
126126 User user = findActiveUser (userId );
127127
128128 if (!passwordEncoder .matches (request .getCurrentPassword (), user .getPassword ())) {
129- throw new UserException (AuthErrorCode .PASSWORD_MISMATCH );
129+ throw new BizException (AuthErrorCode .PASSWORD_MISMATCH );
130130 }
131131
132132 user .changePassword (passwordEncoder .encode (request .getNewPassword ()));
@@ -135,18 +135,18 @@ public void changePassword(Long userId, ChangePasswordRequest request) {
135135
136136 public TokenValidateResponse validateToken (String token ) {
137137 if (!jwtProvider .isTokenValid (token )) {
138- throw new UserException (AuthErrorCode .INVALID_TOKEN );
138+ throw new BizException (AuthErrorCode .INVALID_TOKEN );
139139 }
140140
141141 if (tokenBlacklistRepository .isBlacklisted (token )) {
142- throw new UserException (AuthErrorCode .BLACKLISTED_TOKEN );
142+ throw new BizException (AuthErrorCode .BLACKLISTED_TOKEN );
143143 }
144144
145145 TokenClaims claims = jwtProvider .extractClaims (token );
146146
147147 sessionInvalidationRepository .getInvalidatedAtMillis (claims .userId ()).ifPresent (invalidatedAtMillis -> {
148148 if (jwtProvider .getIssuedAt (token ).getTime () < invalidatedAtMillis ) {
149- throw new UserException (AuthErrorCode .INVALIDATED_SESSION );
149+ throw new BizException (AuthErrorCode .INVALIDATED_SESSION );
150150 }
151151 });
152152
@@ -157,7 +157,7 @@ public TokenValidateResponse validateToken(String token) {
157157
158158 public void sendEmailVerificationCode (String email ) {
159159 if (emailVerificationRepository .hasCode (email )) {
160- throw new UserException (AuthErrorCode .ALREADY_ISSUED_VERIFICATION_CODE );
160+ throw new BizException (AuthErrorCode .ALREADY_ISSUED_VERIFICATION_CODE );
161161 }
162162
163163 String code = verificationCodeGenerator .generate ();
@@ -167,12 +167,12 @@ public void sendEmailVerificationCode(String email) {
167167
168168 public void verifyEmail (String email , String code ) {
169169 if (!emailVerificationRepository .hasCode (email )) {
170- throw new UserException (AuthErrorCode .NOT_ISSUED_VERIFICATION_CODE );
170+ throw new BizException (AuthErrorCode .NOT_ISSUED_VERIFICATION_CODE );
171171 }
172172
173173 String savedCode = emailVerificationRepository .getCode (email );
174174 if (!code .equals (savedCode )) {
175- throw new UserException (AuthErrorCode .INVALID_VERIFICATION_CODE );
175+ throw new BizException (AuthErrorCode .INVALID_VERIFICATION_CODE );
176176 }
177177
178178 emailVerificationRepository .deleteCode (email );
@@ -186,7 +186,7 @@ public void requestPasswordReset(String email) {
186186 }
187187
188188 if (passwordResetRepository .hasToken (email )) {
189- throw new UserException (AuthErrorCode .ALREADY_SENT_PASSWORD_RESET_LINK );
189+ throw new BizException (AuthErrorCode .ALREADY_SENT_PASSWORD_RESET_LINK );
190190 }
191191
192192 String token = passwordResetTokenGenerator .generate ();
@@ -201,11 +201,11 @@ public void requestPasswordReset(String email) {
201201 public void resetPassword (String token , String newPassword ) {
202202 String email = passwordResetRepository .findEmailByToken (token );
203203 if (email == null ) {
204- throw new UserException (AuthErrorCode .INVALID_PASSWORD_RESET_TOKEN );
204+ throw new BizException (AuthErrorCode .INVALID_PASSWORD_RESET_TOKEN );
205205 }
206206
207207 User user = userRepository .findByEmailAndStatus (email , User .Status .ACTIVE )
208- .orElseThrow (() -> new UserException (UserErrorCode .USER_NOT_FOUND ));
208+ .orElseThrow (() -> new BizException (UserErrorCode .USER_NOT_FOUND ));
209209
210210 user .changePassword (passwordEncoder .encode (newPassword ));
211211 sessionInvalidationRepository .invalidate (user .getId (), jwtProvider .getRefreshTokenExpiration ());
@@ -220,13 +220,13 @@ public SocialLinksResponse getSocialLinks(Long userId) {
220220 @ Transactional
221221 public void deleteSocialLink (Long userId , Long socialLinkId ) {
222222 if (!oAuthLinkRepository .existsByIdAndUser_Id (socialLinkId , userId )) {
223- throw new UserException (AuthErrorCode .NOT_REGISTERED_SOCIAL_ACCOUNT );
223+ throw new BizException (AuthErrorCode .NOT_REGISTERED_SOCIAL_ACCOUNT );
224224 }
225225 oAuthLinkRepository .deleteById (socialLinkId );
226226 }
227227
228228 private User findActiveUser (Long userId ) {
229229 return userRepository .findByIdAndStatus (userId , User .Status .ACTIVE )
230- .orElseThrow (() -> new UserException (UserErrorCode .USER_NOT_FOUND ));
230+ .orElseThrow (() -> new BizException (UserErrorCode .USER_NOT_FOUND ));
231231 }
232232}
0 commit comments