Skip to content

Commit

Permalink
feat(rpc/handler): pass payload and/or error to onSuccess and afterHa…
Browse files Browse the repository at this point in the history
…ndle
  • Loading branch information
CheerlessCloud committed Sep 29, 2018
1 parent 370a998 commit 8871b71
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/rpc/Handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ export default class RpcHandler {
await this._message.ack();
}

async onSuccess() {}
async onSuccess(replyPayload: ?Object) {}
async onFail(error: Error) {}
async afterHandle() {}
async afterHandle(error: ?Error, replyPayload: ?Object) {}

async execute() {
let handleError = null;
let replyPayload = null;

try {
await this.beforeHandle();
const replyPayload = await this.handle();
replyPayload = await this.handle();
await this.handleSuccess(replyPayload);
await this.onSuccess();
await this.onSuccess(replyPayload);
} catch (error) {
handleError = error;
try {
Expand All @@ -92,7 +94,7 @@ export default class RpcHandler {
}
} finally {
try {
await this.afterHandle();
await this.afterHandle(handleError, replyPayload);
} catch (err) {
lastErrorHurdle(EError.wrap(err, { handleError }), this);
}
Expand Down

0 comments on commit 8871b71

Please sign in to comment.