Skip to content

Commit c36d1b2

Browse files
committed
Fix incorrect handling of rejected promises returned from middleware interface
1 parent 56233d9 commit c36d1b2

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/driver/koa/KoaDriver.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,11 @@ export class KoaDriver extends BaseDriver {
328328
const middlewareFunctions: Function[] = [];
329329
uses.forEach(use => {
330330
if (use.middleware.prototype && use.middleware.prototype.use) { // if this is function instance of MiddlewareInterface
331-
middlewareFunctions.push((context: any, next: (err?: any) => Promise<any>) => {
331+
middlewareFunctions.push(async (context: any, next: (err?: any) => Promise<any>) => {
332332
try {
333-
const useResult = (getFromContainer(use.middleware) as KoaMiddlewareInterface).use(context, next);
334-
if (isPromiseLike(useResult)) {
335-
useResult.catch((error: any) => {
336-
this.handleError(error, undefined, {
337-
request: context.req,
338-
response: context.res,
339-
context,
340-
next
341-
});
342-
return error;
343-
});
344-
}
345-
346-
return useResult;
333+
return await (getFromContainer(use.middleware) as KoaMiddlewareInterface).use(context, next);
347334
} catch (error) {
348-
this.handleError(error, undefined, {
335+
return await this.handleError(error, undefined, {
349336
request: context.request,
350337
response: context.response,
351338
context,
@@ -423,4 +410,4 @@ export class KoaDriver extends BaseDriver {
423410

424411
return await next();
425412
}
426-
}
413+
}

0 commit comments

Comments
 (0)