LandvibeDev / web-chat-backend

Web Chat Application 🛩
1 stars 3 forks source link

채팅방 입장시 메시지가 없으면 에러 발생 #28

Closed raccoonback closed 4 years ago

raccoonback commented 4 years ago

📝 버그 설명

🏗 추가 이슈

Add any other context about the problem here.

so3500 commented 4 years ago

에러 화면

Request: URL: /api/rooms/6/messages Request Method: GET Status Code: 400 image

원인

public List<Message> getMessagesBy(Long roomId) {
    if (!messageRepository.existsByRoomId(roomId)) {
        throw new NotFoundException(roomId); // <---
    }
    return messageRepository.findAllByRoomId(roomId);
}

메시지가 없을 때 빈 리스트가 반환될 것이므로 미리 검사하는 로직해서 예외를 던지는 로직은 제외해도 상관없을 듯