(
wrapper: InstanceWrapper<NestMiddleware>,
applicationRef: HttpServer,
routeInfo: RouteInfo,
moduleRef: Module,
collection: Map<InjectionToken, InstanceWrapper>,
)
| 243 | } |
| 244 | |
| 245 | private async bindHandler( |
| 246 | wrapper: InstanceWrapper<NestMiddleware>, |
| 247 | applicationRef: HttpServer, |
| 248 | routeInfo: RouteInfo, |
| 249 | moduleRef: Module, |
| 250 | collection: Map<InjectionToken, InstanceWrapper>, |
| 251 | ) { |
| 252 | const { instance, metatype } = wrapper; |
| 253 | |
| 254 | if (isUndefined(instance?.use)) { |
| 255 | throw new InvalidMiddlewareException(metatype!.name); |
| 256 | } |
| 257 | const isStatic = wrapper.isDependencyTreeStatic(); |
| 258 | if (isStatic) { |
| 259 | const proxy = await this.createProxy(instance); |
| 260 | return this.registerHandler(applicationRef, routeInfo, proxy); |
| 261 | } |
| 262 | |
| 263 | const isTreeDurable = wrapper.isDependencyTreeDurable(); |
| 264 | |
| 265 | await this.registerHandler( |
| 266 | applicationRef, |
| 267 | routeInfo, |
| 268 | async <TRequest, TResponse>( |
| 269 | req: TRequest, |
| 270 | res: TResponse, |
| 271 | next: () => void, |
| 272 | ) => { |
| 273 | try { |
| 274 | const contextId = this.getContextId(req, isTreeDurable); |
| 275 | const contextInstance = await this.injector.loadPerContext( |
| 276 | instance, |
| 277 | moduleRef, |
| 278 | collection, |
| 279 | contextId, |
| 280 | ); |
| 281 | const proxy = await this.createProxy<TRequest, TResponse>( |
| 282 | contextInstance, |
| 283 | contextId, |
| 284 | ); |
| 285 | return proxy(req, res, next); |
| 286 | } catch (err) { |
| 287 | let exceptionsHandler = this.exceptionFiltersCache.get(instance.use); |
| 288 | if (!exceptionsHandler) { |
| 289 | exceptionsHandler = this.routerExceptionFilter.create( |
| 290 | instance, |
| 291 | instance.use, |
| 292 | undefined, |
| 293 | ); |
| 294 | this.exceptionFiltersCache.set(instance.use, exceptionsHandler); |
| 295 | } |
| 296 | const host = new ExecutionContextHost([req, res, next]); |
| 297 | exceptionsHandler.next(err, host); |
| 298 | } |
| 299 | }, |
| 300 | ); |
| 301 | } |
| 302 |
no test coverage detected