Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ private UserBasicInfo buildUserBasicInfo(Member member) {
var admin = member.getAdminProfile();
if (admin != null) {
builder.name(admin.getName())
.university(admin.getUniversity().getDisplayName())
.department(admin.getDepartment().getDisplayName())
.major(admin.getMajor().getDisplayName());
.university(admin.getUniversity() != null ? admin.getUniversity().getDisplayName() : null)
.department(admin.getDepartment() != null ? admin.getDepartment().getDisplayName() : null)
.major(admin.getMajor() != null ? admin.getMajor().getDisplayName() : null);
}
}
case PARTNER -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum ErrorStatus implements BaseErrorCode {

// 알리고 SMS 전송 관련 에러
FAILED_TO_SEND_SMS(HttpStatus.INTERNAL_SERVER_ERROR, "ALIGO500", "알리고 SMS 전송에 실패했습니다."),
FAILED_TO_PARSE_ALIGO(HttpStatus.INTERNAL_SERVER_ERROR, "ALIGO500", "알리고 SMS 파싱에 실패했습니다."),

// 인증 에러
NOT_VERIFIED_PHONE_NUMBER(HttpStatus.BAD_REQUEST,"AUTH_4007","전화번호 인증에 실패했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import com.assu.server.infra.aligo.exception.AligoException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Slf4j
@Component
@RequiredArgsConstructor
public class AligoSmsClient {
Expand Down Expand Up @@ -47,13 +50,21 @@ public AligoSendResponse sendSms(String phoneNumber, String message, String name
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.body(BodyInserters.fromFormData(params))
.retrieve()
.onStatus(
status -> status.is4xxClientError() || status.is5xxServerError(),
clientResponse -> clientResponse.bodyToMono(String.class).flatMap(errorBody -> {
log.error("Aligo API 호출 실패. status={}, body={}", clientResponse.statusCode(), errorBody);
return Mono.error(new AligoException(ErrorStatus.FAILED_TO_SEND_SMS));
})
)
.bodyToMono(String.class)
.block(); // 동기로 변환
.block();

try {
return objectMapper.readValue(body, AligoSendResponse.class);
} catch (Exception e) {
throw new AligoException(ErrorStatus.FAILED_TO_SEND_SMS);
log.error("Aligo 응답 파싱 실패. 원본 body: {}", body, e);
throw new AligoException(ErrorStatus.FAILED_TO_PARSE_ALIGO);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ public class AligoSendResponse {
private String result_code; // 성공 여부
private String message; // 결과 메시지
private String msg_id; // 메시지 ID
private String success_cnt; // 성공 개수
private String error_cnt; // 에러 개수
private String msg_type; // 메시지 타입
}