@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 +7 -0
- package/package.json +1 -1
- package/src/json-pipe.js +46 -34
- package/test/StaticS3Loader.js +5 -0
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
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
try {
|
|
79
|
+
// fetch config and apply the folder mapping
|
|
80
|
+
await fetchConfig(state, req);
|
|
81
|
+
await folderMapping(state);
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
97
|
-
}
|
|
98
|
-
const data = dataResponse.body;
|
|
101
|
+
const data = dataResponse.body;
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
109
|
-
|
|
111
|
+
// set last-modified
|
|
112
|
+
updateLastModified(state, response, extractLastModified(dataResponse.headers));
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
// set surrogate key
|
|
115
|
+
response.headers.set('x-surrogate-key', `${contentBusId}${path}`.replace(/\//g, '_'));
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
// Load metadata from metadata.json
|
|
118
|
+
await fetchMetadata(state, req, response);
|
|
119
|
+
await setCustomResponseHeaders(state, req, response);
|
|
117
120
|
|
|
118
|
-
|
|
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
|
}
|
package/test/StaticS3Loader.js
CHANGED
|
@@ -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;
|