-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds try/catch block to increase resilience #666
Changes from 6 commits
ad99d53
178bf6f
1ec5a69
159f3b6
a8affed
d73a9c8
0d6c955
ae99256
7c57144
f0f44f4
3123107
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -14,11 +14,21 @@ class RedisClusterAdapter extends ClusterAdapter { | |||
} | ||||
|
||||
async connect(): Promise<this> { | ||||
return this._connect() | ||||
try{ | ||||
return this._connect() | ||||
} catch (error) { | ||||
console.error('Error connecting to Redis:', error) | ||||
throw error | ||||
} | ||||
} | ||||
|
||||
async send(message: GleeMessage): Promise<void> { | ||||
try{ | ||||
return this._send(message) | ||||
} catch (error) { | ||||
console.error('Error sending message to Redis:', error) | ||||
throw error | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
} | ||||
} | ||||
|
||||
async _connect(): Promise<this> { | ||||
|
KhudaDad414 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,13 +15,19 @@ class HttpClientAdapter extends Adapter { | |||||
return 'HTTP client' | ||||||
} | ||||||
async connect(): Promise<this> { | ||||||
this.emit('connect', { | ||||||
name: this.name(), | ||||||
adapter: this, | ||||||
connection: http, | ||||||
channel: this.channelNames, | ||||||
}) | ||||||
return this | ||||||
try { | ||||||
this.emit('connect', { | ||||||
name: this.name(), | ||||||
adapter: this, | ||||||
connection: http, | ||||||
channel: this.channelNames, | ||||||
}) | ||||||
return this | ||||||
} catch (err) { | ||||||
logWarningMessage(`Failed to Connect: An error occurred while connecting to '${this.name()}' on the '${this.channelNames}' channel. Please review the error details below for further information and corrective action.`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
this.emit('error', err) | ||||||
throw err | ||||||
} | ||||||
} | ||||||
|
||||||
async send(message: GleeMessage): Promise<void> { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,21 @@ class HttpAdapter extends Adapter { | |
} | ||
|
||
async connect(): Promise<this> { | ||
return this._connect() | ||
try { | ||
return this._connect() | ||
} catch (error) { | ||
console.error('Error connecting to HTTP:', error) | ||
throw error | ||
} | ||
} | ||
|
||
async send(message: GleeMessage): Promise<void> { | ||
return this._send(message) | ||
try{ | ||
return this._send(message) | ||
} catch (error) { | ||
console.error('Error sending message to HTTP:', error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also add the channel and the server name to the error so it becomes easier to find the error. |
||
throw error | ||
} | ||
} | ||
|
||
async _readRequestBody(req: http.IncomingMessage): Promise<string> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,11 +37,21 @@ class MqttAdapter extends Adapter { | |
} | ||
|
||
async connect(): Promise<this> { | ||
return this._connect() | ||
try{ | ||
return this._connect() | ||
} catch(error){ | ||
console.error('Error connecting to MQTT:', error) | ||
throw error | ||
} | ||
} | ||
|
||
async send(message: GleeMessage) { | ||
return this._send(message) | ||
try{ | ||
return this._send(message) | ||
} catch(error){ | ||
console.error('Error sending message to MQTT:', error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just like my previouse suggestion, please add the channel and the server where the error occured. |
||
throw error | ||
} | ||
} | ||
|
||
private getSecurityReqs() { | ||
|
@@ -238,6 +248,7 @@ class MqttAdapter extends Adapter { | |
} | ||
|
||
return connectClient() | ||
|
||
} | ||
|
||
_send(message: GleeMessage): Promise<void> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,21 @@ class SocketIOAdapter extends Adapter { | |
} | ||
|
||
async connect(): Promise<this> { | ||
return this._connect() | ||
try { | ||
return this._connect() | ||
} catch(error){ | ||
console.error('Error connecting to Socket.IO:', error) | ||
throw error | ||
} | ||
} | ||
|
||
async send(message: GleeMessage): Promise<void> { | ||
return this._send(message) | ||
try{ | ||
return this._send(message) | ||
} catch(error){ | ||
console.error('Error sending message to Socket.IO:', error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
throw error | ||
} | ||
} | ||
|
||
async _connect(): Promise<this> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,21 @@ class WsClientAdapter extends Adapter { | |
} | ||
|
||
async connect(): Promise<this> { | ||
return this._connect() | ||
try{ | ||
return this._connect() | ||
} catch(error){ | ||
console.error('Error connecting to WS:', error) | ||
throw error | ||
} | ||
} | ||
|
||
async send(message: GleeMessage) { | ||
return this._send(message) | ||
try{ | ||
return this._send(message) | ||
} catch(error){ | ||
console.error('Error sending message to WS:', error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also here. |
||
throw error | ||
} | ||
} | ||
|
||
private async _connect(): Promise<this> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.