Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with calling next Express middleware after sending response #3707

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/api/src/controllers/farmController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ const farmController = {
const { country } = req.body;
if (!country) {
await trx.rollback();
res.status(400).send('No country selected');
return next();
return res.status(400).send('No country selected');
}

const { id, ...units } = await this.getCountry(country);
if (!units) {
await trx.rollback();
res.status(400).send('No unit info for given country');
return next();
return res.status(400).send('No unit info for given country');
}

const utc_offset = await this.getUTCOffsetFromGridPoints(req.body.grid_points);
Expand All @@ -57,14 +55,12 @@ const farmController = {
const new_user = await farmController.getUser(req, trx);
const userFarm = await farmController.insertUserFarm(new_user[0], result.farm_id, trx);
await trx.commit();
res.status(201).send(Object.assign({}, result, userFarm));
return next();
return res.status(201).send(Object.assign({}, result, userFarm));
} catch (error) {
//handle more exceptions
console.log(error);
await trx.rollback();
res.status(400).send(error);
return next();
return res.status(400).send(error);
}
};
},
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/controllers/fieldController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ const fieldController = {
return res.sendStatus(403);
} else {
await trx.commit();
res.status(201).send(result);
req.field = { fieldId: result.field_id, point: result.grid_points[0] };
next();
return res.status(201).send(result);
}
} catch (error) {
//handle more exceptions
Expand Down
Loading