Skip to content

Commit

Permalink
remove un needed error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanPawlett committed May 9, 2020
1 parent e5836e9 commit da28ffc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 39 deletions.
4 changes: 2 additions & 2 deletions services/cards-service/seeds/delete-all.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const axios = require('axios').default;
const getAllIds = () => {
return axios.post('http://localhost/admin/decks/search')
return axios.post('http://localhost:8000/admin/decks/search')
.then(res => res.data.map(d => d._id))
.catch(err => console.log(err.message))
}

const start = async () => {
const ids = await getAllIds();
console.log(ids);
Promise.all(ids.map(id => axios.delete(`http://localhost/admin/decks/${id}`).catch(err => console.log(err.message))))
Promise.all(ids.map(id => axios.delete(`http://localhost:8000/admin/decks/${id}`).catch(err => console.log(err.message))))
.then(() => {
console.log('finished deleting all');
})
Expand Down
52 changes: 27 additions & 25 deletions services/cards-service/seeds/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const postCard = (data, i) => {
}

const postDeck = (data) => {
return axios.post('http://localhost/admin/decks', data)
return axios.post('http://localhost:8000/admin/decks', data)
.then(res => res.data)
.catch(err => {
console.log(err.message);
Expand All @@ -40,33 +40,35 @@ const run = async () => {
const populatedWhiteCards = await populateDeck(whiteCards);
const populatedBlackCards = await populateDeck(blackCards);

const promises = Object.values(decks)
.map(deck => {
const populatedDeck = deck;
//
const blackCardIds = [];
populatedDeck.black.map(index => {
if (populatedBlackCards[index]) {
blackCardIds.push(populatedBlackCards[index]._id);
}
});
delete populatedDeck.black;
populatedDeck.blackCards = blackCardIds;
//
const whiteCardIds = [];
populatedDeck.white.map(index => {
if (populatedWhiteCards[index]) {
whiteCardIds.push(populatedWhiteCards[index]._id);
}
});
delete populatedDeck.white
populatedDeck.whiteCards = whiteCardIds;
for (const deck of Object.values(decks)) {
const populatedDeck = deck;
//
const blackCardIds = [];
populatedDeck.black.map(index => {
if (populatedBlackCards[index]) {
blackCardIds.push(populatedBlackCards[index]._id);
}
});
delete populatedDeck.black;
populatedDeck.blackCards = blackCardIds;
//
const whiteCardIds = [];
populatedDeck.white.map(index => {
if (populatedWhiteCards[index]) {
whiteCardIds.push(populatedWhiteCards[index]._id);
}
});
delete populatedDeck.white
populatedDeck.whiteCards = whiteCardIds;


return postDeck(populatedDeck).catch(err => console.log(err.message));
})
try {
await postDeck(populatedDeck)
} catch (e) {
console.log(e.message);
}
}

await Promise.all(promises);
console.log('done');
}

Expand Down
7 changes: 5 additions & 2 deletions services/games-service/src/games-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ export default class GameService extends Service {
}

private async handleRoomRemoved(ctx: Context<{ _id: string }>) {
const game: any = await this.getGameMatchingRoom(ctx, ctx.params._id);
return this.gameService.destroyGame(game._id);
return this.getGameMatchingRoom(ctx, ctx.params._id)
.then((game) => this.gameService.destroyGame(game._id))
.catch(() => {
// game must not have started yet.
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion services/rooms-service/src/rooms-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export default class RoomsService extends Service {
return Promise.resolve(room);
} else {
// user must be in another room.
throw forbidden('A user is only allowed to join one room at a time');
throw forbidden('You are already in a room.');
}
}

Expand Down
16 changes: 9 additions & 7 deletions services/websocket-gateway-service/src/DefaultNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export default class DefaultNamespace extends BaseNamespace {
// disconnect time added to client.
const timeout = 60 * 1000;
setTimeout(async () => {
const user = await this.broker.call('clients.get', { id: _id }) as any;
const afterTimeoutTime = new Date().getTime();
// If the user hasn't changed socketid or reconnected. Fire a disconnect event.
// tslint:disable-next-line: max-line-length
if (user.socket === client.id && user.disconnectedAt && afterTimeoutTime - user.disconnectedAt > (timeout - 5000)) {
this.broker.emit('websocket-gateway.client.disconnected', { _id });
}
this.broker.call('clients.get', { id: _id })
.then((user: any) => {
const afterTimeoutTime = new Date().getTime();
// If the user hasn't changed socketid or reconnected. Fire a disconnect event.
// tslint:disable-next-line: max-line-length
if (user.socket === client.id && user.disconnectedAt && afterTimeoutTime - user.disconnectedAt > (timeout - 5000)) {
this.broker.emit('websocket-gateway.client.disconnected', { _id });
}
});
}, timeout);
})
// If error, client must have logged out.
Expand Down
5 changes: 3 additions & 2 deletions services/websocket-gateway-service/src/GameNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ export default class GameNamespace extends BaseNamespace {
}

protected async onClientConnect(client: CustomSocket) {
const user: any = await this.broker.call('clients.get', { id: client.user._id });
return this.joinRoom(client.id, user.roomId)
return this.broker.call('clients.get', { id: client.user._id })
.then((user: any) => this.joinRoom(client.id, user.roomId))
.then((res) => {
super.onClientConnect(client);
this.logger.info(res);
return null;
})
.catch(err => {
this.logger.error(err);
// Disconnect the client. Failed to add it to the room.
this.onDisconnect(client);
});
Expand Down

0 comments on commit da28ffc

Please sign in to comment.