feat: expose errors from webhooks
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import express, { Router } from 'express';
|
import express, { Response, Router, NextFunction, RequestHandler } from 'express';
|
||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
|
|
||||||
import { IRequest } from '@automatisch/types';
|
import { IRequest } from '@automatisch/types';
|
||||||
import appConfig from '../config/app';
|
import appConfig from '../config/app';
|
||||||
import webhookHandler from '../controllers/webhooks/handler';
|
import webhookHandler from '../controllers/webhooks/handler';
|
||||||
@@ -16,9 +17,17 @@ router.use(express.text({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.get('/:flowId', webhookHandler);
|
const exposeError = (handler: RequestHandler) => async (req: IRequest, res: Response, next: NextFunction) => {
|
||||||
router.put('/:flowId', webhookHandler);
|
try {
|
||||||
router.patch('/:flowId', webhookHandler);
|
await handler(req, res, next);
|
||||||
router.post('/:flowId', webhookHandler);
|
} catch (err) {
|
||||||
|
res.send(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get('/:flowId', exposeError(webhookHandler));
|
||||||
|
router.put('/:flowId', exposeError(webhookHandler));
|
||||||
|
router.patch('/:flowId', exposeError(webhookHandler));
|
||||||
|
router.post('/:flowId', exposeError(webhookHandler));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
Reference in New Issue
Block a user