-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error handling in event sending and receiving. Resolves #1105
- Loading branch information
Showing
5 changed files
with
124 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const { ServiceBroker } = require(".."); | ||
|
||
const broker1 = new ServiceBroker({ | ||
nodeID: "node-1", | ||
transporter: "NATS" | ||
}); | ||
|
||
const broker2 = new ServiceBroker({ | ||
nodeID: "node-2", | ||
transporter: "NATS" | ||
/*errorHandler(err, info) { | ||
this.logger.warn("Error handled:", err); | ||
}*/ | ||
}); | ||
|
||
broker2.createService({ | ||
name: "test", | ||
|
||
events: { | ||
"test.event": [ | ||
() => { | ||
console.log("Called first handler"); | ||
throw new Error("Error in event handler"); | ||
}, | ||
() => { | ||
console.log("Called second handler"); | ||
} | ||
] | ||
}, | ||
started() {} | ||
}); | ||
|
||
broker1.createService({ | ||
name: "events", | ||
events: { | ||
"test.event": () => { | ||
console.log("Called third handler"); | ||
} | ||
} | ||
}); | ||
|
||
(async function () { | ||
await broker1.start(); | ||
await broker2.start(); | ||
|
||
// broker1.transit.sendEvent = () => Promise.reject(new Error("Unable to send")); | ||
|
||
await broker1.waitForServices("test"); | ||
|
||
try { | ||
await broker1.broadcast("test.event", { a: 5 }, { throwError: true }); | ||
} catch (err) { | ||
broker1.logger.warn("Catched error", err); | ||
} | ||
|
||
broker1.repl(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters