Add error property to socket

This commit is contained in:
Jonathan Staab
2023-03-29 11:08:00 -05:00
parent 8811753ed7
commit 6c4c08c1eb
3 changed files with 8 additions and 7 deletions
+5 -4
View File
@@ -10,6 +10,7 @@ export class Socket {
queue: string[]
bus: EventBus
status: string
error?: Error
_onOpen: (e: any) => void
_onMessage: (e: any) => void
_onError: (e: any) => void
@@ -21,15 +22,14 @@ export class Socket {
READY: "ready",
}
constructor(url: string) {
this.ws = undefined
this.url = url
this.ready = defer()
this.timeout = undefined
this.queue = []
this.bus = new EventBus()
this.status = Socket.STATUS.NEW
this._onOpen = () => {
this.error = undefined
this.status = Socket.STATUS.READY
this.ready.resolve()
this.bus.emit('open')
@@ -43,8 +43,9 @@ export class Socket {
}
}
this._onError = (err: Error) => {
this.bus.emit('error', err)
this._onError = (error: Error) => {
this.error = error
this.bus.emit('error', error)
}
this._onClose = () => {