From c212f667b10c26ea3ce1ec2b2445a6f4f9d2635f Mon Sep 17 00:00:00 2001 From: WoH Date: Tue, 14 Sep 2021 23:11:02 +0200 Subject: [PATCH] fix: Cast errors in a backwards-compatible way --- packages/cli/src/routeGeneration/templates/express.hbs | 4 ++-- packages/cli/src/routeGeneration/templates/hapi.hbs | 5 +++-- packages/cli/src/routeGeneration/templates/koa.hbs | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/routeGeneration/templates/express.hbs b/packages/cli/src/routeGeneration/templates/express.hbs index 0a04af334..68f1ccd6d 100644 --- a/packages/cli/src/routeGeneration/templates/express.hbs +++ b/packages/cli/src/routeGeneration/templates/express.hbs @@ -81,7 +81,7 @@ export function RegisterRoutes(app: express.Router) { let validatedArgs: any[] = []; try { validatedArgs = getValidatedArgs(args, request, response); - } catch (err: any) { + } catch (err) { return next(err); } @@ -156,7 +156,7 @@ export function RegisterRoutes(app: express.Router) { request['user'] = await promiseAny(secMethodOrPromises); next(); } - catch(err: any) { + catch(err) { // Show most recent error as response const error = failedAttempts.pop(); error.status = error.status || 401; diff --git a/packages/cli/src/routeGeneration/templates/hapi.hbs b/packages/cli/src/routeGeneration/templates/hapi.hbs index e7f0b0bf0..fbf30cf02 100644 --- a/packages/cli/src/routeGeneration/templates/hapi.hbs +++ b/packages/cli/src/routeGeneration/templates/hapi.hbs @@ -101,7 +101,8 @@ export function RegisterRoutes(server: any) { let validatedArgs: any[] = []; try { validatedArgs = getValidatedArgs(args, request, h); - } catch (error: any) { + } catch (err) { + const error = err as any; if (isBoom(error)) { throw error; } @@ -186,7 +187,7 @@ export function RegisterRoutes(server: any) { request['user'] = await promiseAny(secMethodOrPromises); return request['user']; } - catch(err: any) { + catch(err) { // Show most recent error as response const error = failedAttempts.pop(); if (isBoom(error)) { diff --git a/packages/cli/src/routeGeneration/templates/koa.hbs b/packages/cli/src/routeGeneration/templates/koa.hbs index c54c04c48..6716837cb 100644 --- a/packages/cli/src/routeGeneration/templates/koa.hbs +++ b/packages/cli/src/routeGeneration/templates/koa.hbs @@ -82,7 +82,8 @@ export function RegisterRoutes(router: KoaRouter) { let validatedArgs: any[] = []; try { validatedArgs = getValidatedArgs(args, context, next); - } catch (error: any) { + } catch (err) { + const error = err as any; context.status = error.status; context.throw(error.status, JSON.stringify({ fields: error.fields })); } @@ -155,7 +156,7 @@ export function RegisterRoutes(router: KoaRouter) { success = true; context.request['user'] = user; } - catch(err: any) { + catch(err) { // Show most recent error as response const error = failedAttempts.pop(); context.status = error.status || 401;