Proper handling for kernel level errors

This commit is contained in:
Garrett Mills 2020-09-05 10:10:00 -05:00
parent f1301d24f7
commit c0e1e1d2a4
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -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,6 +60,7 @@ export default class Kernel extends AppClass {
public async handle(request: Request): Promise<Request> {
const logger = this.make(Logging)
try {
for (const module of this.preflight.toArray()) {
logger.verbose(`Applying pre-flight HTTP kernel module: ${module.constructor.name}`)
request = await module.apply(request)
@ -73,6 +75,11 @@ export default class Kernel extends AppClass {
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
}