@quintype/framework 7.26.1 → 7.26.2-amp-infinite-scroll-errors.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.
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash -e
2
2
 
3
- npm install --legacy-peer-deps
3
+ npm install
4
4
  git diff --quiet
5
5
  npm run docs
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.26.1",
3
+ "version": "7.26.2-amp-infinite-scroll-errors.0",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -8,7 +8,7 @@
8
8
  "npm": "^8.5.0"
9
9
  },
10
10
  "scripts": {
11
- "prepublishOnly": "npm test && ./bin-dev-scripts/standard-version-release.sh",
11
+ "prepublishOnly": "./bin-dev-scripts/standard-version-release.sh",
12
12
  "test": "NODE_ENV=test npx mocha --recursive --require ./test/babel",
13
13
  "watch-test": "NODE_ENV=test npx mocha --recursive --watch --require ./test/babel",
14
14
  "coverage": "nyc --all npm test",
@@ -20,11 +20,19 @@ async function storyPageInfiniteScrollHandler(req, res, next, { client, config,
20
20
  infiniteScrollSource,
21
21
  });
22
22
  const jsonResponse = await infiniteScrollAmp.getResponse();
23
- if (jsonResponse instanceof Error) return next(jsonResponse);
23
+ if (jsonResponse instanceof Error) return handleErrorResponse(res, next, jsonResponse);
24
24
  res.set("Content-Type", "application/json; charset=utf-8");
25
25
  setCorsHeaders({ req, res, next, publisherConfig: config });
26
26
 
27
27
  if (!res.headersSent) return res.send(jsonResponse);
28
28
  }
29
29
 
30
+ function handleErrorResponse(res, next, error) {
31
+ const errorMessage = error.message;
32
+ if (errorMessage === `Query param "story-id" missing`) {
33
+ return res.status(400).send(errorMessage);
34
+ }
35
+ return next(errorMessage);
36
+ }
37
+
30
38
  module.exports = { storyPageInfiniteScrollHandler };
@@ -13,10 +13,11 @@ function isUrl(url) {
13
13
  function processRedirects(req, res, next, sourceUrlArray, urls) {
14
14
  const query = url.parse(req.url, true) || {};
15
15
  const search = query.search || "";
16
+ if (!urls || !sourceUrlArray || !Array.isArray(urls) || !Array.isArray(sourceUrlArray)) return;
16
17
 
17
18
  sourceUrlArray.some((sourceUrl) => {
18
- try {
19
- if (urls[sourceUrl]) {
19
+ if (urls[sourceUrl]) {
20
+ try {
20
21
  const destinationPath = urls[sourceUrl].destinationUrl;
21
22
  const extractedSourceUrl = match(sourceUrl, {
22
23
  decode: decodeURIComponent,
@@ -51,9 +52,9 @@ function processRedirects(req, res, next, sourceUrlArray, urls) {
51
52
  return true;
52
53
  }
53
54
  }
55
+ } catch (err) {
56
+ console.log(`Redirection error on host: '${req.host}' url: '${sourceUrl}'`, err);
54
57
  }
55
- } catch (err) {
56
- console.log(`Redirection error on ${req.host}-----`, err);
57
58
  }
58
59
  });
59
60
  }