core: use bail to traigger route events

pull/148/head
undefined 3 years ago
parent bdf2d972cd
commit fd2ac84535

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.26.20",
"version": "2.26.21",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",

@ -665,17 +665,21 @@ async function handle(ctx, HandlerClass, checker) {
throw new MethodNotAllowedError(method);
}
await bus.serial('handler/init', h);
await bus.serial(`handler/before-prepare/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail('handler/init', h);
await bus.bail(`handler/before-prepare/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail('handler/before-prepare', h);
if (h._prepare) await h._prepare(args);
if (h.prepare) await h.prepare(args);
await bus.serial(`handler/before/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail(`handler/before/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail('handler/before', h);
if (h[method]) await h[method](args);
if (operation) await h[`post${operation}`](args);
await bus.serial(`handler/after/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail(`handler/after/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail('handler/after', h);
if (h.cleanup) await h.cleanup(args);
if (h.finish) await h.finish(args);
await bus.serial(`handler/finish/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail(`handler/finish/${HandlerClass.name.replace(/Handler$/, '')}`, h);
await bus.bail('handler/finish', h);
} catch (e) {
try {
await h.onerror(e);

Loading…
Cancel
Save