diff --git a/lib/src/http/kernel/Kernel.ts b/lib/src/http/kernel/Kernel.ts index dc45d16..fb0571f 100644 --- a/lib/src/http/kernel/Kernel.ts +++ b/lib/src/http/kernel/Kernel.ts @@ -5,6 +5,7 @@ import {Collection} from '../../collection/Collection.ts' import {Service} from '../../../../di/src/decorator/Service.ts' import {Request} from '../Request.ts' import {Logging} from '../../service/logging/Logging.ts' +import {error} from '../response/helpers.ts' /** * Interface for fluently registering kernel modules into the kernel. @@ -59,19 +60,25 @@ export default class Kernel extends AppClass { public async handle(request: Request): Promise { const logger = this.make(Logging) - for ( const module of this.preflight.toArray() ) { - logger.verbose(`Applying pre-flight HTTP kernel module: ${module.constructor.name}`) - request = await module.apply(request) - } - - if ( this.inflight ) { - logger.verbose(`Applying core HTTP kernel module: ${this.inflight.constructor.name}`) - request = await this.inflight.apply(request) - } - - for ( const module of this.postflight.toArray() ) { - logger.verbose(`Applying post-flight HTTP kernel module: ${module.constructor.name}`) - request = await module.apply(request) + try { + for (const module of this.preflight.toArray()) { + logger.verbose(`Applying pre-flight HTTP kernel module: ${module.constructor.name}`) + request = await module.apply(request) + } + + if (this.inflight) { + logger.verbose(`Applying core HTTP kernel module: ${this.inflight.constructor.name}`) + request = await this.inflight.apply(request) + } + + for (const module of this.postflight.toArray()) { + logger.verbose(`Applying post-flight HTTP kernel module: ${module.constructor.name}`) + request = await module.apply(request) + } + } catch (e: any) { + logger.error(e) + const error_response = error(e) + await error_response.write(request) } return request