Skip to content

Commit

Permalink
Wrap single handler invocations with try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Feb 26, 2021
1 parent 119f91a commit f8877fe
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
import camelCase = require("lodash.camelcase");
import { EventHandler } from "./handler/handler";
import { warn } from "./log/console";
import { prepareStatus } from "./message";
import { toArray } from "./util";

export function wrapEventHandler(eh: EventHandler): EventHandler {
return async ctx => {
if (Array.isArray(ctx.data)) {
const results = [];
for (const event of ctx.data) {
const result = await eh({ ...ctx, data: event });
if (result) {
results.push(result);
try {
const result = await eh({ ...ctx, data: event });
if (result) {
results.push(result);
}
} catch (e) {
results.push(prepareStatus(e, ctx));
}
}
return {
Expand Down

0 comments on commit f8877fe

Please sign in to comment.