Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
refactor: there is no logic reason to throw here
Browse files Browse the repository at this point in the history
  • Loading branch information
severo committed Jan 21, 2020
1 parent 767c365 commit 893e00a
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/socket.io/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Constants } from './constants'
import { Guard, ConsoleLogger } from '../shared/index'
import {
ConnectionEvent,
InternalServerErrorEvent,
// InternalServerErrorEvent,
UpdateUserNameEvent,
} from '../domain/events'
import { User } from '../domain'
Expand All @@ -16,16 +16,7 @@ class Socket {
this.io
.of('/occupapp-beta')
.on(ConnectionEvent.eventName, (socket: SocketIOClient.Socket) => {
let socketUser: User
try {
socketUser = this.getOrCreateUser(socket.id)
} catch (e) {
this.log.error(
'User could not be created or obtained on connection',
e.message
)
this.emitInternalServerError(socket, e)
}
const socketUser: User = this.getOrCreateUser(socket.id)

socket.on(
UpdateUserNameEvent.eventName,
Expand Down Expand Up @@ -121,13 +112,13 @@ class Socket {
return user
}

private emitInternalServerError(socket: SocketIOClient.Socket, error: Error) {
let internalServerErrorEvent = new InternalServerErrorEvent(error)
socket.emit(
InternalServerErrorEvent.eventName,
this.toException(internalServerErrorEvent.error)
)
}
// private emitInternalServerError(socket: SocketIOClient.Socket, error: Error) {
// let internalServerErrorEvent = new InternalServerErrorEvent(error)
// socket.emit(
// InternalServerErrorEvent.eventName,
// this.toException(internalServerErrorEvent.error)
// )
// }

private toException = (error: Error): Exception => {
return {
Expand Down

0 comments on commit 893e00a

Please sign in to comment.