From 7ef309c3199a9d508670bc93f29e243787fefc87 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 30 Dec 2022 16:25:04 +0530 Subject: [PATCH] docs: fix examples --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3b2d0d..6b650f9 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,9 @@ The final handler is executed when the entire middleware chain ends by calling ` const context = { stack: [], } -const middleware = new Middleware() + +type MiddlewareFn = (ctx: typeof context, next: NextFn) +const middleware = new Middleware() middleware.add((ctx: typeof context, next: NextFn) => { ctx.stack.push('fn1') @@ -117,7 +119,9 @@ To simply the exception handling process, you can define a custom error handler const context = { stack: [], } -const middleware = new Middleware() + +type MiddlewareFn = (ctx: typeof context, next: NextFn) +const middleware = new Middleware() middleware.add((ctx: typeof context, next: NextFn) => { ctx.stack.push('middleware 1 upstream') @@ -150,6 +154,7 @@ await middleware assert.deepEqual(context.stack, [ 'middleware 1 upstream', 'middleware 2 upstream', + 'error handler', 'middleware 1 downstream' ]) ```