@apolitical/server 2.3.0-rc.fallback.4 → 2.3.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "2.3.0-rc.fallback.4",
3
+ "version": "2.3.0",
4
4
  "description": "Node.js module to encapsulate Apolitical's express server setup",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@ module.exports = ({
12
12
  }) => {
13
13
  const { BODY_PARSER_OPTIONS, CORS_OPTIONS } = config.SERVER;
14
14
 
15
- return function load(app, { staticFiles, corsOptions, prerenderToken }) {
15
+ return function load(app, { corsOptions, prerenderToken, staticFiles }) {
16
16
  const childLogger = logger.where(__filename, 'load');
17
17
  childLogger.debug('Started');
18
18
  // Load useful middlewares
@@ -45,11 +45,14 @@ module.exports =
45
45
  }
46
46
 
47
47
  if (redirectURL) {
48
- res.redirect(TEMPORARY_REDIRECT, `${redirectURL}?errorMessage=${encodeURI(message)}`);
49
- } else if (fallbackController && message === 'Unexpected error: Cannot read items') {
50
- fallbackController(req, res);
51
- } else {
52
- res.status(code).json({ message, errors });
48
+ return res.redirect(TEMPORARY_REDIRECT, `${redirectURL}?errorMessage=${encodeURI(message)}`);
49
+ }
50
+ if (fallbackController) {
51
+ // more known error messages can be added here
52
+ if (message === 'Unexpected error: Cannot read items') {
53
+ return fallbackController(req, res);
54
+ }
53
55
  }
56
+ return res.status(code).json({ message, errors });
54
57
  };
55
58
  };
@@ -52,10 +52,8 @@ module.exports = ({
52
52
  }
53
53
  // Load documentation
54
54
  documentationLoader(app, opts);
55
-
56
- // Load static resources or fallback
55
+ // Load fallback routing
57
56
  fallbackLoader(app, opts);
58
-
59
57
  // Use error handler
60
58
  if (opts.handleErrors) {
61
59
  app.use(errorMiddleware(opts));