aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/async.ts12
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 @@
1import { eachSeries } from 'async' 1import { eachSeries } from 'async'
2import { NextFunction, Request, RequestHandler, Response } from 'express' 2import { NextFunction, Request, RequestHandler, Response } from 'express'
3import { 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
24function 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
25export { 34export {
26 asyncMiddleware 35 asyncMiddleware,
36 asyncRetryTransactionMiddleware
27} 37}