diff options
Diffstat (limited to 'server/middlewares/async.ts')
-rw-r--r-- | server/middlewares/async.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/server/middlewares/async.ts b/server/middlewares/async.ts index dd209b115..f770bc120 100644 --- a/server/middlewares/async.ts +++ b/server/middlewares/async.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { eachSeries } from 'async' | 1 | import { eachSeries } from 'async' |
2 | import { NextFunction, Request, RequestHandler, Response } from 'express' | 2 | import { NextFunction, Request, RequestHandler, Response } from 'express' |
3 | import { retryTransactionWrapper } from '../helpers/database-utils' | ||
3 | 4 | ||
4 | // Syntactic sugar to avoid try/catch in express controllers | 5 | // Syntactic sugar to avoid try/catch in express controllers |
5 | // Thanks: https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016 | 6 | // Thanks: https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016 |
@@ -20,8 +21,17 @@ function asyncMiddleware (fun: RequestPromiseHandler | RequestPromiseHandler[]) | |||
20 | } | 21 | } |
21 | } | 22 | } |
22 | 23 | ||
24 | function asyncRetryTransactionMiddleware (fun: RequestPromiseHandler) { | ||
25 | return (req: Request, res: Response, next: NextFunction) => { | ||
26 | return Promise.resolve( | ||
27 | retryTransactionWrapper(fun, req, res, next) | ||
28 | ).catch(err => next(err)) | ||
29 | } | ||
30 | } | ||
31 | |||
23 | // --------------------------------------------------------------------------- | 32 | // --------------------------------------------------------------------------- |
24 | 33 | ||
25 | export { | 34 | export { |
26 | asyncMiddleware | 35 | asyncMiddleware, |
36 | asyncRetryTransactionMiddleware | ||
27 | } | 37 | } |