diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-13 14:27:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-13 14:27:40 +0200 |
commit | 90d4bb8125e80c8060416d4d135ddeaf0a622ede (patch) | |
tree | b3b7181329a08ecc930b54fe7b48095c4155393c /server/middlewares | |
parent | 3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (diff) | |
download | PeerTube-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.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 | } |