@adobe/helix-html-pipeline 1.8.5 → 1.8.6

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.8.6](https://github.com/adobe/helix-html-pipeline/compare/v1.8.5...v1.8.6) (2022-11-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handle errors when loading config ([#181](https://github.com/adobe/helix-html-pipeline/issues/181)) ([a6e61a9](https://github.com/adobe/helix-html-pipeline/commit/a6e61a98cffe41bb22795c3a262c95cdf869f06f)), closes [#179](https://github.com/adobe/helix-html-pipeline/issues/179)
7
+
1
8
  ## [1.8.5](https://github.com/adobe/helix-html-pipeline/compare/v1.8.4...v1.8.5) (2022-10-31)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/json-pipe.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+ import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
12
13
  import fetchMetadata from './steps/fetch-metadata.js';
13
14
  import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
14
15
  import { PipelineResponse } from './PipelineResponse.js';
@@ -16,6 +17,7 @@ import jsonFilter from './utils/json-filter.js';
16
17
  import { extractLastModified, updateLastModified } from './utils/last-modified.js';
17
18
  import fetchConfig from './steps/fetch-config.js';
18
19
  import { getPathInfo } from './utils/path.js';
20
+ import { PipelineStatusError } from './PipelineStatusError.js';
19
21
 
20
22
  /**
21
23
  * Checks the fstab for folder mapping entries and then re-adjusts the path infos if needed.
@@ -73,47 +75,57 @@ export async function jsonPipe(state, req) {
73
75
  });
74
76
  }
75
77
 
76
- // fetch config and apply the folder mapping
77
- await fetchConfig(state, req);
78
- await folderMapping(state);
78
+ try {
79
+ // fetch config and apply the folder mapping
80
+ await fetchConfig(state, req);
81
+ await folderMapping(state);
79
82
 
80
- // fetch data from content bus
81
- const { path } = state.info;
82
- state.timer?.update('json-fetch');
83
- let dataResponse = await s3Loader.getObject('helix-content-bus', `${contentBusId}/${partition}${path}`);
83
+ // fetch data from content bus
84
+ const { path } = state.info;
85
+ state.timer?.update('json-fetch');
86
+ let dataResponse = await s3Loader.getObject('helix-content-bus', `${contentBusId}/${partition}${path}`);
84
87
 
85
- // if not found, fall back to code bus
86
- if (dataResponse.status === 404) {
87
- dataResponse = await s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}${path}`);
88
- }
88
+ // if not found, fall back to code bus
89
+ if (dataResponse.status === 404) {
90
+ dataResponse = await s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}${path}`);
91
+ }
89
92
 
90
- // if still not found, return status
91
- if (dataResponse.status !== 200) {
92
- if (dataResponse.status < 500) {
93
- await fetchMetadata(state, req, dataResponse);
94
- await setCustomResponseHeaders(state, req, dataResponse);
93
+ // if still not found, return status
94
+ if (dataResponse.status !== 200) {
95
+ if (dataResponse.status < 500) {
96
+ await fetchMetadata(state, req, dataResponse);
97
+ await setCustomResponseHeaders(state, req, dataResponse);
98
+ }
99
+ return dataResponse;
95
100
  }
96
- return dataResponse;
97
- }
98
- const data = dataResponse.body;
101
+ const data = dataResponse.body;
99
102
 
100
- // filter data
101
- const response = jsonFilter(state, data, {
102
- limit: limit ? Number.parseInt(limit, 10) : undefined,
103
- offset: offset ? Number.parseInt(offset, 10) : undefined,
104
- sheet,
105
- raw: limit === undefined && offset === undefined && sheet === undefined,
106
- });
103
+ // filter data
104
+ const response = jsonFilter(state, data, {
105
+ limit: limit ? Number.parseInt(limit, 10) : undefined,
106
+ offset: offset ? Number.parseInt(offset, 10) : undefined,
107
+ sheet,
108
+ raw: limit === undefined && offset === undefined && sheet === undefined,
109
+ });
107
110
 
108
- // set last-modified
109
- updateLastModified(state, response, extractLastModified(dataResponse.headers));
111
+ // set last-modified
112
+ updateLastModified(state, response, extractLastModified(dataResponse.headers));
110
113
 
111
- // set surrogate key
112
- response.headers.set('x-surrogate-key', `${contentBusId}${path}`.replace(/\//g, '_'));
114
+ // set surrogate key
115
+ response.headers.set('x-surrogate-key', `${contentBusId}${path}`.replace(/\//g, '_'));
113
116
 
114
- // Load metadata from metadata.json
115
- await fetchMetadata(state, req, response);
116
- await setCustomResponseHeaders(state, req, response);
117
+ // Load metadata from metadata.json
118
+ await fetchMetadata(state, req, response);
119
+ await setCustomResponseHeaders(state, req, response);
117
120
 
118
- return response;
121
+ return response;
122
+ } catch (e) {
123
+ const res = new PipelineResponse('', {
124
+ status: e instanceof PipelineStatusError ? e.code : 500,
125
+ });
126
+ const level = res.status >= 500 ? 'error' : 'info';
127
+ log[level](`pipeline status: ${res.status} ${e.message}`, e);
128
+ res.headers.set('x-error', cleanupHeaderValue(e.message));
129
+ return res;
130
+ }
119
131
  }
@@ -34,6 +34,11 @@ export class StaticS3Loader {
34
34
  body: '',
35
35
  headers: new Map(),
36
36
  };
37
+ if (response instanceof Error) {
38
+ // eslint-disable-next-line no-console
39
+ console.log(`StaticS3Loader: failing ${bucketId}/${key} -> ${response.message}`);
40
+ throw response;
41
+ }
37
42
  // eslint-disable-next-line no-console
38
43
  console.log(`StaticS3Loader: loading ${bucketId}/${key} -> ${response.status}`);
39
44
  return response;