@quintype/framework 7.26.2-amp-infinite-scroll-errors.1 → 7.26.2-amp-infinite-scroll-errors.2

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": "@quintype/framework",
3
- "version": "7.26.2-amp-infinite-scroll-errors.1",
3
+ "version": "7.26.2-amp-infinite-scroll-errors.2",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -6,6 +6,8 @@ const cloneDeep = require("lodash/cloneDeep");
6
6
 
7
7
  // eslint-disable-next-line consistent-return
8
8
  async function storyPageInfiniteScrollHandler(req, res, next, { client, config, ...rest }) {
9
+ if (!req.query["story-id"]) return res.status(400).send(`Query param "story-id" missing`);
10
+
9
11
  const ampConfig = await config.memoizeAsync("amp-config", async () => await AmpConfig.getAmpConfig(client));
10
12
  const opts = cloneDeep(rest);
11
13
  const infiniteScrollSource = get(opts, ["featureConfig", "infiniteScroll", "source"], "collection");
@@ -20,19 +22,11 @@ async function storyPageInfiniteScrollHandler(req, res, next, { client, config,
20
22
  infiniteScrollSource,
21
23
  });
22
24
  const jsonResponse = await infiniteScrollAmp.getResponse();
23
- if (jsonResponse instanceof Error) return handleErrorResponse(res, next, jsonResponse);
25
+ if (jsonResponse instanceof Error) return next(jsonResponse);
24
26
  res.set("Content-Type", "application/json; charset=utf-8");
25
27
  setCorsHeaders({ req, res, next, publisherConfig: config });
26
28
 
27
29
  if (!res.headersSent) return res.send(jsonResponse);
28
30
  }
29
31
 
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
-
38
32
  module.exports = { storyPageInfiniteScrollHandler };