Catch all middleware errors

This commit is contained in:
D. Berge
2020-08-24 13:25:14 +02:00
parent 2ed52f1a54
commit 721dae4084
13 changed files with 66 additions and 28 deletions

View File

@@ -27,7 +27,6 @@ module.exports = async function (req, res, next) {
res.status(204).send();
next();
} catch (err) {
console.error(err);
next(err);
}

View File

@@ -3,7 +3,11 @@ const { event } = require('../../../lib/db');
module.exports = async function (req, res, next) {
res.status(200).send(await event.list(req.params.project, req.query));
next();
try {
res.status(200).send(await event.list(req.params.project, req.query));
next();
} catch (err) {
next(err);
}
};

View File

@@ -4,7 +4,7 @@ const { event } = require('../../../lib/db');
module.exports = async function (req, res, next) {
try {
const payload = Object.assign({}, req.body);
const payload = req.body;
if (req.params.type) {
payload.type = req.params.type;
@@ -31,7 +31,6 @@ module.exports = async function (req, res, next) {
res.status(201).send();
next();
} catch (err) {
console.error(err);
next(err);
}

View File

@@ -4,7 +4,7 @@ const { event } = require('../../../lib/db');
module.exports = async function (req, res, next) {
try {
const payload = Object.assign({}, req.body);
const payload = req.body;
if (req.params.type) {
payload.type = req.params.type;
@@ -31,7 +31,6 @@ module.exports = async function (req, res, next) {
res.status(201).send();
next();
} catch (err) {
console.error(err);
next(err);
}

View File

@@ -3,7 +3,11 @@ const { gis } = require('../../../../lib/db');
module.exports = async function (req, res, next) {
res.status(200).send(await gis.project.bbox(req.params.project));
next();
try {
res.status(200).send(await gis.project.bbox(req.params.project));
next();
} catch (err) {
next(err);
}
};

View File

@@ -30,8 +30,12 @@ module.exports = async function (req, res, next) {
const options = makeOptions(req.query);
res.set("Cache-Control", "public, max-age=30");
res.status(200).send(await handler(req.params.project, options));
next();
try {
res.set("Cache-Control", "public, max-age=30");
res.status(200).send(await handler(req.params.project, options));
next();
} catch (err) {
next(err);
}
};

View File

@@ -34,8 +34,12 @@ module.exports = async function (req, res, next) {
const options = makeOptions(req.query);
res.set("Cache-Control", "public, max-age=30");
res.status(200).send(await handler(req.params.project, options));
next();
try {
res.set("Cache-Control", "public, max-age=30");
res.status(200).send(await handler(req.params.project, options));
next();
} catch (err) {
next(err);
}
};

View File

@@ -30,7 +30,11 @@ module.exports = async function (req, res, next) {
const options = makeOptions(req.query);
res.status(200).send(await handler(req.params.project, options));
next();
try {
res.status(200).send(await handler(req.params.project, options));
next();
} catch (err) {
next(err);
}
};

View File

@@ -3,7 +3,11 @@ const { label } = require('../../../lib/db');
module.exports = async function (req, res, next) {
res.status(200).send(await label.list(req.params.project, req.query));
next();
try {
res.status(200).send(await label.list(req.params.project, req.query));
next();
} catch (err) {
next(err);
}
};

View File

@@ -3,7 +3,11 @@ const { line } = require('../../../lib/db');
module.exports = async function (req, res, next) {
res.status(200).send(await line.list(req.params.project, req.query));
next();
try {
res.status(200).send(await line.list(req.params.project, req.query));
next();
} catch (err) {
next(err);
}
};

View File

@@ -3,7 +3,11 @@ const { project} = require('../../../lib/db');
module.exports = async function (req, res, next) {
res.status(200).send(await project.summary(req.params.project));
next();
try {
res.status(200).send(await project.summary(req.params.project));
next();
} catch (err) {
next(err);
}
};

View File

@@ -3,7 +3,12 @@ const { project} = require('../../../lib/db');
module.exports = async function (req, res, next) {
res.status(200).send(await project.list());
next();
try {
res.status(200).send(await project.list());
next();
} catch (err) {
next(err);
}
};

View File

@@ -3,8 +3,12 @@ const { sequence } = require('../../../lib/db');
module.exports = async function (req, res, next) {
console.log(req.query);
res.status(200).send(await sequence.list(req.params.project, req.query));
next();
try {
res.status(200).send(await sequence.list(req.params.project, req.query));
next();
} catch (err) {
next(err);
}
};