ti2 1.0.26 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +9 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -24,6 +24,9 @@ const cache = require('./cache');
24
24
  const rebuild = fn => obj =>
25
25
  Object.fromEntries(Object.entries(obj).flatMap(([k, v]) => fn(k, v)));
26
26
 
27
+ const isNumber = value => !Number.isNaN(Number(value));
28
+
29
+
27
30
  module.exports = async ({
28
31
  apiDocs = true,
29
32
  elasticLogIndex = 'apilog_ti2',
@@ -201,17 +204,16 @@ module.exports = async ({
201
204
  }
202
205
  connect(app);
203
206
  app.use(middleware.mock());
207
+ app.use((req, res) => res.sendStatus(404));
204
208
  // global error Handling
205
209
  app.use((err, req, res) => {
206
- if (process.env.CONSOLE_ERRORS) {
210
+ if (process.env.CONSOLE_ERRORS || process.env.JEST_WORKER_ID) {
207
211
  console.error(err);
208
212
  }
209
- // console.log(req.headers.['X-Request-Id'], err);
210
- res.status(err.status || 500);
211
- if ((process.env.JEST_WORKER_ID)) {
212
- console.debug(err);
213
- }
214
- return res.json({
213
+ return res.status((() => {
214
+ if (!isNumber(err.status)) return 500;
215
+ return Number(err.status);
216
+ })()).json({
215
217
  message: err.message || 'Internal Error',
216
218
  });
217
219
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2",
3
- "version": "1.0.26",
3
+ "version": "1.0.29",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {