Skip to content

Commit e8655db

Browse files
committed
feat: Add response handling and error checking to POST /messages/:id/like
- Check if messageWithIdAsNumber exists after incrementing likes - Notify all waiting clients via callBacksForNewMessages callbacks - Send updated message with 200 status on success - Return 404 error if message not found - Enable real-time like updates via long polling - Improve error handling for invalid message IDs
1 parent ee7c2c1 commit e8655db

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

chat-app/backend/server.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ app.post("/messages/:id/like", (req, res) => {
7878
);
7979

8080
messageWithIdAsNumber.likes += 1;
81+
82+
if (messageWithIdAsNumber) {
83+
while (callBacksForNewMessages.length > 0) {
84+
const callback = callBacksForNewMessages.pop();
85+
86+
callback([messageWithIdAsNumber]);
87+
}
88+
res.status(200).send(messageWithIdAsNumber);
89+
} else {
90+
res.status(404).send("Message not found");
91+
}
8192
});
8293

8394
// Start the server

0 commit comments

Comments
 (0)