Skip to content

Commit

Permalink
Reduce duplicated error handling when the clusterMasterHandler is a g…
Browse files Browse the repository at this point in the history
…enerator
  • Loading branch information
johnteee committed Jun 28, 2018
1 parent f10e60b commit 3cf79ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ wsgilite.addClusterMasterRequestHandler(async (worker, msg, handle) => {
wsgilite.GET('/requestActionOnClusterMaster', async function (request, response, meta) {
// {"event":"MSG_WSGILITE_DO_THINGS_WORKER_SUCCESS","result":[{"data":"user01"}]}
return wsgilite.requestActionOnClusterMaster({action: 'readrecord'}).catch((e)=>{
console.log(e);
console.log(`I got error: ${e.errorMessage}`);
return e.errorMessage;
});
});
Expand Down
2 changes: 1 addition & 1 deletion demo/simple-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ wsgilite.addClusterMasterRequestHandler(async (worker, msg, handle) => {
wsgilite.GET('/requestActionOnClusterMaster', async function (request, response, meta) {
// {"event":"MSG_WSGILITE_DO_THINGS_WORKER_SUCCESS","result":[{"data":"user01"}]}
return wsgilite.requestActionOnClusterMaster({action: 'readrecord'}).catch((e)=>{
console.log(e);
console.log(`I got error: ${e.errorMessage}`);
return e.errorMessage;
});
});
Expand Down
6 changes: 4 additions & 2 deletions wsgilite.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,15 @@ class WSGILite extends DefSubRoute {
}
handleClusterMasterRequest(worker, msg, handle) {
let result = [];
let errorHandled = false;

const self = this;
const errorHandler = (e) => {
console.log(e);
if (worker) {
if (worker && (!errorHandled)) {
console.log(e);
worker.send({event: MSG_WSGILITE_DO_THINGS_WORKER_FAILURE, error: e, errorMessage: e.toString(), errorStacktrace: e.stacktrace});
}
errorHandled = true;
return Promise.reject(e);
};
return MonadIO.generatorToPromise(function *() {
Expand Down

0 comments on commit 3cf79ba

Please sign in to comment.