Refactor error message

This commit is contained in:
gparant 2020-04-04 17:56:43 +02:00
parent 53e1600e67
commit f04d1342b5
2 changed files with 7 additions and 7 deletions

View File

@ -41,8 +41,8 @@ export class IoSocketController{
socket.on('join-room', (message : string) => { socket.on('join-room', (message : string) => {
let messageUserPosition = this.hydrateMessageReceive(message); let messageUserPosition = this.hydrateMessageReceive(message);
if(!messageUserPosition){ if(messageUserPosition instanceof Error){
return socket.emit("message-error", JSON.stringify({message: "Error format message"})) return socket.emit("message-error", JSON.stringify({message: messageUserPosition.message}))
} }
//join user in room //join user in room
socket.join(messageUserPosition.roomId); socket.join(messageUserPosition.roomId);
@ -53,8 +53,8 @@ export class IoSocketController{
socket.on('user-position', (message : string) => { socket.on('user-position', (message : string) => {
let messageUserPosition = this.hydrateMessageReceive(message); let messageUserPosition = this.hydrateMessageReceive(message);
if(!messageUserPosition){ if(messageUserPosition instanceof Error){
return socket.emit("message-error", JSON.stringify({message: "Error format message"})); return socket.emit("message-error", JSON.stringify({message: messageUserPosition.message}));
} }
// sending to all clients in room except sender // sending to all clients in room except sender
this.saveUserPosition((socket as ExSocketInterface), messageUserPosition); this.saveUserPosition((socket as ExSocketInterface), messageUserPosition);
@ -69,12 +69,12 @@ export class IoSocketController{
} }
//Hydrate and manage error //Hydrate and manage error
hydrateMessageReceive(message : string) : MessageUserPosition | null{ hydrateMessageReceive(message : string) : MessageUserPosition | Error{
try { try {
return new MessageUserPosition(message); return new MessageUserPosition(message);
}catch (err) { }catch (err) {
//TODO log error //TODO log error
return null; return new Error(err);
} }
} }
} }

View File

@ -7,7 +7,7 @@ export class Point implements PointInterface{
constructor(x : number, y : number) { constructor(x : number, y : number) {
if(!x || !y){ if(!x || !y){
throw Error("x and y cannot be null"); throw Error("position x and y cannot be null");
} }
this.x = x; this.x = x;
this.y = y; this.y = y;