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
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "paravel", "name": "paravel",
"version": "0.1.10", "version": "0.1.11",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "paravel", "name": "paravel",
"version": "0.1.10", "version": "0.1.11",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"husky": "^8.0.3", "husky": "^8.0.3",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "paravel", "name": "paravel",
"version": "0.1.10", "version": "0.1.11",
"description": "Yet another toolkit for nostr", "description": "Yet another toolkit for nostr",
"repository": { "repository": {
"type": "git", "type": "git",
+5 -4
View File
@@ -10,6 +10,7 @@ export class Socket {
queue: string[] queue: string[]
bus: EventBus bus: EventBus
status: string status: string
error?: Error
_onOpen: (e: any) => void _onOpen: (e: any) => void
_onMessage: (e: any) => void _onMessage: (e: any) => void
_onError: (e: any) => void _onError: (e: any) => void
@@ -21,15 +22,14 @@ export class Socket {
READY: "ready", READY: "ready",
} }
constructor(url: string) { constructor(url: string) {
this.ws = undefined
this.url = url this.url = url
this.ready = defer() this.ready = defer()
this.timeout = undefined
this.queue = [] this.queue = []
this.bus = new EventBus() this.bus = new EventBus()
this.status = Socket.STATUS.NEW this.status = Socket.STATUS.NEW
this._onOpen = () => { this._onOpen = () => {
this.error = undefined
this.status = Socket.STATUS.READY this.status = Socket.STATUS.READY
this.ready.resolve() this.ready.resolve()
this.bus.emit('open') this.bus.emit('open')
@@ -43,8 +43,9 @@ export class Socket {
} }
} }
this._onError = (err: Error) => { this._onError = (error: Error) => {
this.bus.emit('error', err) this.error = error
this.bus.emit('error', error)
} }
this._onClose = () => { this._onClose = () => {