Skip to content

Commit

Permalink
[backend] user が居なかった時のエラーハンドリングを適切に行う (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
kotto5 authored Feb 26, 2024
1 parent b921be0 commit 65f4404
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions backend/src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ export class ChatService {
}

handleDisconnect(client: Socket) {
const emitData = {
userId: this.getUserId(client),
status: UserStatus.Offline,
name: this.getUser(client)?.name,
};
if (emitData.userId) {
client.broadcast.emit('online-status', [emitData]);
const user = this.getUser(client);
if (user) {
client.broadcast.emit('online-status', [
{
userId: user.id,
status: UserStatus.Offline,
name: user.name,
},
]);
}
this.removeClient(client);
}
Expand Down

0 comments on commit 65f4404

Please sign in to comment.