Proper handling for kernel level errors
This commit is contained in:
parent
f1301d24f7
commit
c0e1e1d2a4
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user