Skip to content

Commit

Permalink
fix(templates): fix error handling and route method call
Browse files Browse the repository at this point in the history
  • Loading branch information
ruidias-commercetools committed Jul 22, 2024
1 parent c263563 commit f91c4fe
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
12 changes: 9 additions & 3 deletions application-templates/javascript/event/src/routes/event.route.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { Router } from 'express';

import { logger } from '../utils/logger.utils.js';
import { post } from '../controllers/event.controller.js';

const eventRouter = Router();

eventRouter.post('/', async (req, res) => {
eventRouter.post('/', async (req, res, next) => {
logger.info('Event message received');
res.status(200);
res.send();

try {
await post(req.body);
res.status(200).send();
} catch (error) {
next(error);
}
});

export default eventRouter;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const jobRouter = Router();
jobRouter.post('/', async (req, res, next) => {
try {
await post(req, res);
next();
res.status(200).send();
} catch (error) {
next(error);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Router } from 'express';
import { logger } from '../utils/logger.utils.js';
import { post } from '../controllers/service.controller.js';

const serviceRouter = Router();

serviceRouter.post('/', async (req, res) => {
serviceRouter.post('/', async (req, res, next) => {
logger.info('Cart update extension executed');
res.status(200);
res.send();

try {
// Add your custom logic here
await post(req.body);
res.status(200).send();
} catch (error) {
next(error);
}
});

export default serviceRouter;
11 changes: 8 additions & 3 deletions application-templates/typescript/event/src/routes/event.route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Router } from 'express';

import { logger } from '../utils/logger.utils';
import { post } from '../controllers/event.controller';

const eventRouter: Router = Router();

eventRouter.post('/', async (req, res) => {
eventRouter.post('/', async (req, res, next) => {
logger.info('Event message received');
res.status(200);
res.send();
try {
await post(req, res);
res.status(200).send();
} catch (error) {
next(error);
}
});

export default eventRouter;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const jobRouter: Router = Router();
jobRouter.post('/', async (req, res, next) => {
try {
await post(req, res);
next();
res.status(200).send();
} catch (error) {
next(error);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Router } from 'express';
import { logger } from '../utils/logger.utils';
import { post } from '../controllers/service.controller';

const serviceRouter = Router();

serviceRouter.post('/', async (req, res) => {
logger.info('Cart update extension executed');
res.status(200);
res.send();
serviceRouter.post('/', async (req, res, next) => {
logger.info('Service post message received');

try {
await post(req, res);
res.status(200).send();
} catch (error) {
next(error);
}
});

export default serviceRouter;
export default serviceRouter;

0 comments on commit f91c4fe

Please sign in to comment.