@Override
    public void run() {
        try {
            while (true) {
                Message message = chatModel.receiveMessage();
                MessageHandler messageHandler = MessageHandlerFactory.getMessageHandler(message, chatView, chatModel);
                messageHandler.handleMessage();
            }
        } catch (ConnectionLostException e) {
            chatView.showErrorMessage("Server is unavailable");
            clearChat();
        } catch (UnknownMessageException e) {
            chatView.showErrorMessage(e.getMessage());
        } catch (MessageHandlerException e) {
            clearChat();
        }
    }