diff --git a/src/compose.ts b/src/compose.ts index 83ae97b3..a4e1481c 100644 --- a/src/compose.ts +++ b/src/compose.ts @@ -37,6 +37,8 @@ export const compose = ( ): ((context: C, next?: Function) => Promise) => { return (context, next) => { let index = -1 + const isContext = context instanceof Context + return dispatch(0) /** @@ -58,7 +60,7 @@ export const compose = ( if (middleware[i]) { handler = middleware[i][0][0] - if (context instanceof Context) { + if (isContext) { context.req.routeIndex = i } } else { @@ -66,7 +68,7 @@ export const compose = ( } if (!handler) { - if (context instanceof Context && context.finalized === false && onNotFound) { + if (isContext && context.finalized === false && onNotFound) { res = await onNotFound(context) } } else { @@ -75,7 +77,7 @@ export const compose = ( return dispatch(i + 1) }) } catch (err) { - if (err instanceof Error && context instanceof Context && onError) { + if (err instanceof Error && isContext && onError) { context.error = err res = await onError(err, context) isError = true