diff --git a/packages/runtime-handler/src/dev-runtime/internal/functionRunner.ts b/packages/runtime-handler/src/dev-runtime/internal/functionRunner.ts index d54a0f86..e1979fcc 100644 --- a/packages/runtime-handler/src/dev-runtime/internal/functionRunner.ts +++ b/packages/runtime-handler/src/dev-runtime/internal/functionRunner.ts @@ -70,7 +70,7 @@ process.on('uncaughtException', (err, origin) => { process.on( 'message', - ({ functionPath, event, config, path }: FunctionRunnerOptions) => { + async ({ functionPath, event, config, path }: FunctionRunnerOptions) => { try { setRoutes(config.routes); constructGlobalScope(config); @@ -110,7 +110,11 @@ process.on( `Could not find a "handler" function in file ${functionPath}` ); } - handler(context, event, callback); + if (handler.constructor.name === 'AsyncFunction') { + await handler(context, event, callback); + } else { + handler(context, event, callback); + } } catch (err) { if (process.send) { process.send({ err: serializeError(err) }); diff --git a/packages/runtime-handler/src/dev-runtime/route.ts b/packages/runtime-handler/src/dev-runtime/route.ts index 4dfdad31..76a122db 100644 --- a/packages/runtime-handler/src/dev-runtime/route.ts +++ b/packages/runtime-handler/src/dev-runtime/route.ts @@ -157,13 +157,13 @@ export function constructContext( }> { function getTwilioClient(opts?: TwilioClientOptions): TwilioClient { checkForValidAccountSid(env.ACCOUNT_SID, { - shouldPrintMessage: true, + shouldPrintMessage: logger ? !!logger.error : false, shouldThrowError: true, functionName: 'context.getTwilioClient()', logger: logger, }); checkForValidAuthToken(env.AUTH_TOKEN, { - shouldPrintMessage: true, + shouldPrintMessage: logger ? !!logger.error : false, shouldThrowError: true, functionName: 'context.getTwilioClient()', logger: logger, @@ -221,12 +221,13 @@ export function handleError( err: Error | string | object, req: ExpressRequest, res: ExpressResponse, - functionFilePath?: string + functionFilePath?: string, + logger?: LoggerInstance ) { res.status(500); if (isError(err)) { const cleanedupError = cleanUpStackTrace(err); - + logger?.error(cleanedupError.toString()); if (req.useragent && (req.useragent.isDesktop || req.useragent.isMobile)) { res.type('text/html'); res.send(wrapErrorInHtml(cleanedupError, functionFilePath)); @@ -334,7 +335,7 @@ export function functionPathToRoute( if (err) { const error = deserializeError(err); - handleError(error, req, res, functionPath); + handleError(error, req, res, functionPath, config.logger); } if (reply) {