Skip to content

Commit

Permalink
hotfix: Xquare DSM 외부 login API 예외 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Aug 19, 2024
1 parent 8ea3ec1 commit f55ae6c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.example.whopper.global.security.jwt.JwtTokenProvider;
import com.example.whopper.infra.feign.XquareClient;
import com.example.whopper.infra.feign.dto.response.XquareUserResponse;
import com.example.whopper.infra.feign.exception.XquareException;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
Expand All @@ -34,9 +35,9 @@ public class StudentLoginService implements StudentLoginUseCase {

@Transactional
public TokenResponse studentLogin(LoginRequest request) {
return studentMongoRepository.existsByAccountId(request.accountId()) ?
loginExistingStudent(request) :
registerAndLoginNewStudent(request);
return studentMongoRepository.existsByAccountId(request.accountId())
? loginExistingStudent(request)
: registerAndLoginNewStudent(request);
}

private TokenResponse loginExistingStudent(LoginRequest request) {
Expand All @@ -51,7 +52,14 @@ private TokenResponse loginExistingStudent(LoginRequest request) {
}

private TokenResponse registerAndLoginNewStudent(LoginRequest request) {
XquareUserResponse xquareUserResponse = xquareClient.xquareUser(request);
XquareUserResponse xquareUserResponse;

try {
xquareUserResponse = xquareClient.xquareUser(request);
} catch (Exception e) {
throw XquareException.EXCEPTION;
}

if(!xquareUserResponse.getUserRole().equals("STU")) throw InvalidUserException.EXCEPTION;
StudentEntity newStudent = createAndSaveNewStudent(xquareUserResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.example.whopper.global.security.jwt.JwtTokenProvider;
import com.example.whopper.infra.feign.XquareClient;
import com.example.whopper.infra.feign.dto.response.XquareUserResponse;
import com.example.whopper.infra.feign.exception.XquareException;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -43,7 +44,14 @@ private TokenResponse loginExistingTeacher(LoginRequest request) {
}

private TokenResponse registerAndLoginNewTeacher(LoginRequest request) {
XquareUserResponse xquareUserResponse = xquareClient.xquareUser(request);
XquareUserResponse xquareUserResponse;

try {
xquareUserResponse = xquareClient.xquareUser(request);
} catch (Exception e) {
throw XquareException.EXCEPTION;
}

if(!xquareUserResponse.getUserRole().equals("SCH")) throw InvalidUserException.EXCEPTION;
TeacherEntity newTeacher = createAndSaveNewTeacher(xquareUserResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ public record LoginRequest(
String accountId,
String password
) {
public LoginRequest {
accountId = accountId.toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ErrorCode {

// xquare
XQUARE(503, "DSM-login 서비스에서 에러가 발생했습니다."),

FORBIDDEN(403, "접근 권한이 없는 유저입니다."),

// auth
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.whopper.infra.feign.exception;

import com.example.whopper.global.error.exception.ErrorCode;
import com.example.whopper.global.error.exception.WhopperException;

public class XquareException extends WhopperException {
public static final WhopperException EXCEPTION = new XquareException();

private XquareException() {
super(ErrorCode.XQUARE);
}

}

0 comments on commit f55ae6c

Please sign in to comment.