aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
committerChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
commit90d4bb8125e80c8060416d4d135ddeaf0a622ede (patch)
treeb3b7181329a08ecc930b54fe7b48095c4155393c /server/middlewares
parent3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (diff)
downloadPeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.gz
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.zst
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.zip
Refractor retry transaction function
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}