예외 메시지 다국어 처리를 위한 키 기반 구조 도입

This commit is contained in:
2025-12-22 16:39:06 +09:00
parent 6fa0667120
commit ff1b8aa413
5 changed files with 104 additions and 33 deletions

View File

@@ -316,11 +316,9 @@ class ChatRoomService(
@Transactional(readOnly = true)
fun isMyRoomSessionActive(member: Member, chatRoomId: Long): Boolean {
val room = chatRoomRepository.findByIdAndIsActiveTrue(chatRoomId)
?: throw SodaException("채팅방을 찾을 수 없습니다.")
val participant = participantRepository.findByChatRoomAndMemberAndIsActiveTrue(room, member)
if (participant == null) {
throw SodaException("잘못된 접근입니다")
}
?: throw SodaException(messageKey = "chat.error.room_not_found")
participantRepository.findByChatRoomAndMemberAndIsActiveTrue(room, member)
?: throw SodaException(messageKey = "common.error.access_denied")
return fetchSessionActive(room.sessionId)
}
@@ -328,7 +326,7 @@ class ChatRoomService(
fun enterChatRoom(member: Member, chatRoomId: Long, characterImageId: Long? = null): ChatRoomEnterResponse {
// 1) 활성 여부 무관하게 방 조회
val baseRoom = chatRoomRepository.findById(chatRoomId).orElseThrow {
SodaException("채팅방을 찾을 수 없습니다.")
SodaException(messageKey = "chat.error.room_not_found")
}
// 2) 기본 방 기준 참여/활성 여부 확인
@@ -342,10 +340,10 @@ class ChatRoomService(
ParticipantType.CHARACTER
) ?: baseRoom.participants.firstOrNull {
it.participantType == ParticipantType.CHARACTER
} ?: throw SodaException("잘못된 접근입니다")
} ?: throw SodaException(messageKey = "common.error.invalid_request")
val baseCharacter = baseCharacterParticipant.character
?: throw SodaException("오류가 발생했습니다. 다시 시도해 주세요.")
?: throw SodaException(messageKey = "common.error.unknown")
// 4) 유효한 입장 대상 방 결정
val effectiveRoom: ChatRoom = if (isActiveRoom && isMyActiveParticipation) {
@@ -355,9 +353,9 @@ class ChatRoomService(
val alt = chatRoomRepository.findActiveChatRoomByMemberAndCharacter(member, baseCharacter)
alt ?: ( // 대체 방이 없으면 기존과 동일하게 예외 처리
if (!isActiveRoom) {
throw SodaException("채팅방을 찾을 수 없습니다.")
throw SodaException(messageKey = "chat.error.room_not_found")
} else {
throw SodaException("잘못된 접근입니다")
throw SodaException(messageKey = "common.error.invalid_request")
}
)
}
@@ -368,10 +366,10 @@ class ChatRoomService(
ParticipantType.CHARACTER
) ?: effectiveRoom.participants.firstOrNull {
it.participantType == ParticipantType.CHARACTER
} ?: throw SodaException("잘못된 접근입니다")
} ?: throw SodaException(messageKey = "common.error.invalid_request")
val character = characterParticipant.character
?: throw SodaException("오류가 발생했습니다. 다시 시도해 주세요.")
?: throw SodaException(messageKey = "common.error.unknown")
val imageUrl = "$imageHost/${character.imagePath ?: "profile/default-profile.png"}"
val characterDto = ChatRoomEnterCharacterDto(