Skip to content

Commit

Permalink
Support error catching in middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Feb 24, 2023
1 parent 02d5382 commit 574ea10
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/builder/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ export async function executeWithMiddleware<E extends Interaction>(
last: MiddlewareResult<E, any>
): Promise<MiddlewareResult<Interaction, any> | void> => {
const fn = middlewares[index];
if (fn == null) return last;

if (fn == null) {
await callback({
event: last.event as E,
ctx: last.ctx,
});

return;
}

const result = await fn({
event: last.event,
Expand All @@ -54,15 +62,8 @@ export async function executeWithMiddleware<E extends Interaction>(
if (result != null) return result;
};

const params = await callRecursive(0, {
await callRecursive(0, {
event,
ctx: {},
});

if (params != null) {
return await callback({
event: params.event as E,
ctx: params.ctx,
});
}
}

0 comments on commit 574ea10

Please sign in to comment.