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 { IRequest } from '@automatisch/types';
|
||||
import appConfig from '../config/app';
|
||||
import webhookHandler from '../controllers/webhooks/handler';
|
||||
@@ -16,9 +17,17 @@ router.use(express.text({
|
||||
},
|
||||
}));
|
||||
|
||||
router.get('/:flowId', webhookHandler);
|
||||
router.put('/:flowId', webhookHandler);
|
||||
router.patch('/:flowId', webhookHandler);
|
||||
router.post('/:flowId', webhookHandler);
|
||||
const exposeError = (handler: RequestHandler) => async (req: IRequest, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await handler(req, res, next);
|
||||
} 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;
|
||||
|
Reference in New Issue
Block a user