debug: delay websocket close and detail auth error

This commit is contained in:
Hamza-Ayed
2026-05-29 01:27:20 +03:00
parent 87ec54bbd7
commit 83f8d6ab65
2 changed files with 14 additions and 12 deletions

View File

@@ -213,14 +213,14 @@ export class Hub {
if (!client.userID) {
if (base.type !== protocol.TypeAuthenticate) {
client.send(protocol.newError(protocol.ErrTokenInvalid, 'Authentication required'));
client.close();
setTimeout(() => client.close(), 200);
return;
}
const { session_id, user_id } = base;
if (!session_id || !user_id) {
client.send(protocol.newError(protocol.ErrTokenInvalid, 'Missing session_id or user_id'));
client.close();
setTimeout(() => client.close(), 200);
return;
}
@@ -228,13 +228,13 @@ export class Hub {
const sess = this.store.getSession(session_id);
if (!sess) {
client.send(protocol.newError(protocol.ErrSessionNotFound, 'No active session found'));
client.close();
setTimeout(() => client.close(), 200);
return;
}
if (sess.status === 'ended') {
client.send(protocol.newError(protocol.ErrSessionNotFound, 'Session already ended'));
client.close();
setTimeout(() => client.close(), 200);
return;
}
@@ -244,19 +244,19 @@ export class Hub {
role = 'driver';
if (sess.driverConn) {
client.send(protocol.newError(protocol.ErrSessionExists, 'Driver already connected'));
client.close();
setTimeout(() => client.close(), 200);
return;
}
} else if (user_id === sess.passengerID) {
role = 'passenger';
if (sess.passengerConn) {
client.send(protocol.newError(protocol.ErrSessionExists, 'Passenger already connected'));
client.close();
setTimeout(() => client.close(), 200);
return;
}
} else {
client.send(protocol.newError(protocol.ErrUnauthorizedUser, 'User not authorized for this session'));
client.close();
client.send(protocol.newError(protocol.ErrUnauthorizedUser, `User not authorized for this session. Got: ${user_id}, expected driver: ${sess.driverID} or passenger: ${sess.passengerID}`));
setTimeout(() => client.close(), 200);
return;
}