Skip to content

Commit

Permalink
perf(app-autoload): add init error catch
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Aug 16, 2021
1 parent 9c851da commit 995946c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/app-autoload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export async function getApps(opts: AppAutoload): Promise<AppConfig[]> {

export default fp(async function (instance: FastifyInstance, opts: AppAutoload | AppsLoaded) {

// eslint-disable-next-line @typescript-eslint/init-declarations
let apps: AppConfig[];
if ((opts as AppsLoaded).apps) {
apps = (opts as AppsLoaded).apps;
Expand All @@ -216,9 +217,17 @@ export default fp(async function (instance: FastifyInstance, opts: AppAutoload |
}

for await (const appConfig of apps) {
await instance.register(load.bind(null, appConfig), {
prefix: appConfig.prefix,
});
try {
await instance.register(load.bind(null, appConfig), {
prefix: appConfig.prefix,
});
}
catch (e) {
instance.log.fatal({
app: appConfig.name,
err: e
});
}
}

return;
Expand Down

0 comments on commit 995946c

Please sign in to comment.