From 90d4bb8125e80c8060416d4d135ddeaf0a622ede Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 13 Jun 2018 14:27:40 +0200 Subject: Refractor retry transaction function --- server/middlewares/async.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'server/middlewares') 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 @@ import { eachSeries } from 'async' import { NextFunction, Request, RequestHandler, Response } from 'express' +import { retryTransactionWrapper } from '../helpers/database-utils' // Syntactic sugar to avoid try/catch in express controllers // Thanks: https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016 @@ -20,8 +21,17 @@ function asyncMiddleware (fun: RequestPromiseHandler | RequestPromiseHandler[]) } } +function asyncRetryTransactionMiddleware (fun: RequestPromiseHandler) { + return (req: Request, res: Response, next: NextFunction) => { + return Promise.resolve( + retryTransactionWrapper(fun, req, res, next) + ).catch(err => next(err)) + } +} + // --------------------------------------------------------------------------- export { - asyncMiddleware + asyncMiddleware, + asyncRetryTransactionMiddleware } -- cgit v1.2.3