Skip to content

Commit f49df52

Browse files
Merge pull request #1295 from opencomponents/custom-status-code
add option to send custom status code back to the registry
2 parents 12da5b8 + 1c7257d commit f49df52

File tree

6 files changed

+64
-17
lines changed

6 files changed

+64
-17
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"multer": "1.4.3",
113113
"nice-cache": "0.0.5",
114114
"oc-client": "4.0.1",
115-
"oc-client-browser": "1.5.7",
115+
"oc-client-browser": "1.5.8",
116116
"oc-empty-response-handler": "1.0.2",
117117
"oc-get-unix-utc-timestamp": "1.0.6",
118118
"oc-s3-storage-adapter": "1.2.0",
@@ -136,4 +136,4 @@
136136
"universalify": "^2.0.0",
137137
"yargs": "17.3.0"
138138
}
139-
}
139+
}

src/registry/routes/helpers/get-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export default function getComponent(conf: Config, repository: Repository) {
275275
err ||
276276
new Error(strings.errors.registry.DATA_OBJECT_IS_UNDEFINED);
277277
return callback({
278-
status: 500,
278+
status: Number(err.status) || 500,
279279
response: {
280280
code: 'GENERIC_ERROR',
281281
error: strings.errors.registry.COMPONENT_EXECUTION_ERROR(
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
module.exports = {
4+
package: {
5+
name: 'async-custom-error-component',
6+
version: '1.0.0',
7+
oc: {
8+
container: false,
9+
renderInfo: false,
10+
files: {
11+
template: {
12+
type: 'jade',
13+
hashKey: '8c1fbd954f2b0d8cd5cf11c885fed4805225749f',
14+
src: 'template.js'
15+
},
16+
dataProvider: {
17+
type: 'node.js',
18+
hashKey: '123457',
19+
src: 'server.js'
20+
}
21+
}
22+
}
23+
},
24+
data: '"use strict";module.exports.data = function(ctx, cb){cb(Object.assign(new Error(), {status: 404}));};',
25+
view:
26+
'var oc=oc||{};oc.components=oc.components||{},oc.components["8c1fbd954f2b0d8cd5cf11c885fed4805225749f"]' +
27+
'=function(){var o=[];return o.push("<div>hello</div>"),o.join("")};'
28+
};

test/fixtures/mocked-components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
'async-error2-component': require('./async-error2'),
66
'async-error3-component': require('./async-error3'),
77
'async-error4-component': require('./async-error4'),
8+
'async-custom-error-component': require('./async-custom-error'),
89
'error-component': require('./error'),
910
'npm-component': require('./npm'),
1011
'plugin-component': require('./plugin'),

test/unit/registry-routes-helpers-get-component.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ describe('registry : routes : helpers : get-component', () => {
135135
});
136136
});
137137

138+
describe('when the component sends a custom status code', () => {
139+
before(done => {
140+
initialise(mockedComponents['async-custom-error-component']);
141+
const getComponent = GetComponent({}, mockedRepository);
142+
143+
getComponent(
144+
{
145+
name: 'async-custom-error-component',
146+
headers: {},
147+
version: '1.X.X',
148+
conf: { baseUrl: 'http://components.com/' }
149+
},
150+
() => done()
151+
);
152+
});
153+
154+
it.only('should return that status code to the client', () => {
155+
expect(fireStub.args[0][1].status).to.equal(404);
156+
});
157+
});
158+
138159
describe('when rendering a component with a legacy template', () => {
139160
describe("when oc-client requests an unrendered component and it doesn't provide templates header", () => {
140161
const headers = {

yarn.lock

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,7 @@
24052405
dependencies:
24062406
"prettier-linter-helpers" "^1.0.0"
24072407

2408-
"eslint-scope@^5.1.1":
2408+
"eslint-scope@^5.1.1", "[email protected]":
24092409
"integrity" "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw=="
24102410
"resolved" "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz"
24112411
"version" "5.1.1"
@@ -2421,14 +2421,6 @@
24212421
"esrecurse" "^4.3.0"
24222422
"estraverse" "^5.2.0"
24232423

2424-
2425-
"integrity" "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw=="
2426-
"resolved" "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz"
2427-
"version" "5.1.1"
2428-
dependencies:
2429-
"esrecurse" "^4.3.0"
2430-
"estraverse" "^4.1.1"
2431-
24322424
"eslint-utils@^3.0.0":
24332425
"integrity" "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA=="
24342426
"resolved" "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz"
@@ -2518,7 +2510,12 @@
25182510
"resolved" "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz"
25192511
"version" "4.3.0"
25202512

2521-
"estraverse@^5.1.0", "estraverse@^5.2.0":
2513+
"estraverse@^5.1.0":
2514+
"integrity" "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA=="
2515+
"resolved" "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz"
2516+
"version" "5.3.0"
2517+
2518+
"estraverse@^5.2.0":
25222519
"integrity" "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA=="
25232520
"resolved" "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz"
25242521
"version" "5.3.0"
@@ -3858,10 +3855,10 @@
38583855
"resolved" "https://registry.npmjs.org/oc-client-browser/-/oc-client-browser-1.5.4.tgz"
38593856
"version" "1.5.4"
38603857

3861-
3862-
"integrity" "sha512-TO7FVwJ+FDcrejXWjVkpp1ddgG/7No1nWZGs552iOz8m+Gqfq6ES+d2hnUXz7BtH4GrDr6l9RQwJhci+fqIQtQ=="
3863-
"resolved" "https://registry.npmjs.org/oc-client-browser/-/oc-client-browser-1.5.7.tgz"
3864-
"version" "1.5.7"
3858+
3859+
"integrity" "sha512-2EKANYx7u0Vm1qYfU328L3P28KzZTTUJB2Dkbic4/WhE+WskBmdPfJyGoufuJBipXygvlqqXQ5lnaZ6Roq0JuQ=="
3860+
"resolved" "https://registry.npmjs.org/oc-client-browser/-/oc-client-browser-1.5.8.tgz"
3861+
"version" "1.5.8"
38653862
dependencies:
38663863
"universalify" "2.0.0"
38673864

0 commit comments

Comments
 (0)