-
-
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
Conversation
@KhudaDad414 |
Hi @KhudaDad414 I made the suggested changes. Please have a look and give your valuable suggestions. |
@ankur0904 can you reset the auto format changes? it's hard to know what changes you have made. secondly the try/catch block should only be in this is what I mean: class Adapter {
// This is your main public method for establishing a connection
public async connect() {
try {
await this._connect();
} catch (error) {
// Handle or rethrow the error as needed
}
}
// The actual connection logic is encapsulated here
private async _connect() {
// Your connection logic goes here
}
// The public method for sending data
public async send() {
try {
await this._send(data);
} catch (error) {
// Handle error
}
}
// The actual sending logic is handled privately here
private async _send() {
// Your sending logic goes here
}
} |
@KhudaDad414 I tried to reset the auto format change. I have undo the last commit, removed the auto format manually, then recommitted the changes, got the merge conflict, and resolved the merge conflict. I'll take your code as a reference and update the PR soon. Thanks |
824bac6
to
178bf6f
Compare
Pull Request Test Coverage Report for Build 7558836827
💛 - Coveralls |
src/adapters/cluster/redis/index.ts
Outdated
} | ||
|
||
async _connect(): Promise<this> { | ||
try { |
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.
we don't want to catch the error since we left the error handling the _connect
method. errors thrown by this function will be handled by the connect method.
try { |
src/adapters/cluster/redis/index.ts
Outdated
} catch (error) { | ||
console.error('Error connecting to Redis:', error) | ||
throw error | ||
} |
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.
} catch (error) { | |
console.error('Error connecting to Redis:', error) | |
throw error | |
} |
src/adapters/http/server.ts
Outdated
@@ -164,6 +174,7 @@ class HttpAdapter extends Adapter { | |||
} | |||
|
|||
async _connect(): Promise<this> { | |||
try { |
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.
try { |
src/adapters/http/server.ts
Outdated
} catch (error) { | ||
console.error(error) | ||
throw error | ||
} |
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.
} catch (error) { | |
console.error(error) | |
throw error | |
} |
const scramSha512SecurityReq = securityRequirements.find( | ||
(sec) => sec.type() === 'scramSha512' | ||
) | ||
async _connect() { |
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.
you have removed the public method. the functionality won't work anymore. connect
method is used for error handling and _connect
for the actual logic. we always call the _connect
method from the connect
method.
src/adapters/mqtt/index.ts
Outdated
} catch (error) { | ||
console.error(error) | ||
throw error | ||
} |
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.
} catch (error) { | |
console.error(error) | |
throw error | |
} |
src/adapters/socket.io/index.ts
Outdated
} | ||
|
||
async _connect(): Promise<this> { | ||
try { |
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.
try { |
src/adapters/socket.io/index.ts
Outdated
} catch (error) { | ||
console.error('An error occurred while connecting:', error) | ||
throw error | ||
} |
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.
} catch (error) { | |
console.error('An error occurred while connecting:', error) | |
throw error | |
} |
src/adapters/ws/client.ts
Outdated
} | ||
|
||
private async _connect(): Promise<this> { | ||
try{ |
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.
try{ |
src/adapters/ws/client.ts
Outdated
}catch (error) { | ||
console.error('An error occurred while connecting:', error) | ||
throw error | ||
} |
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.
}catch (error) { | |
console.error('An error occurred while connecting:', error) | |
throw error | |
} |
Sorry @KhudaDad414 for making the mistake. Now I fully understand that |
I request you to please review the changes in src/adapters/kafka/index.ts this file. |
since this file doesn't have a |
@KhudaDad414 I added the |
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.
Left some comments.
src/adapters/cluster/redis/index.ts
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
throw error |
src/adapters/cluster/redis/index.ts
Outdated
return this._send(message) | ||
} catch (error) { | ||
console.error('Error sending message to Redis:', error) |
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.
console.error('Error sending message to Redis:', error) | |
const errorMessage = `Failed to send message on channel '${message.channel}' to server '${message.serverName}'`; | |
this.emit('error', new Error(errorMessage)); | |
this.emit('error', error) |
src/adapters/http/client.ts
Outdated
}) | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
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.`) | |
logWarningMessage(`Failed to Connect: An error occurred while connecting to '${this.name()}'. Please review the error details below for further information and corrective action.`) |
src/adapters/http/server.ts
Outdated
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 comment
The 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.
src/adapters/mqtt/index.ts
Outdated
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 comment
The 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.
src/adapters/socket.io/index.ts
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
src/adapters/ws/client.ts
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
also here.
@ankur0904 do you need some help here? |
I'm so sorry @KhudaDad414 for the late response. I have made the required changes in the latest commit. Thanks |
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.
LGTM!
@ankur0904 the tests are failing. |
fbf2b99
to
ae99256
Compare
@KhudaDad414 Please look at the updated changes. |
Hey @ankur0904 the SonarCloud is complaining about the code duplication. And it has a point. all of the code here is duplicated. 😆 let's make it simpler. for for |
@ankur0904 just wrap the |
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
@KhudaDad414 a.instance.send(msg).catch((e: Error) => {
this._processError(errorMiddlewares, e, msg)
}) & this._clusterAdapter.instance.send(message).catch((e: Error) => {
this._processError(this._router.getErrorMiddlewares(), e, message)
}) |
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.
LGTM
@KhudaDad414 |
/rtm |
🎉 This PR is included in version 0.36.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
http
adapterRelated issue(s)
Fixes #640