Skip to content

Commit 56aab8b

Browse files
add option to send custom status code back to the registry
1 parent 12da5b8 commit 56aab8b

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

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 = {

0 commit comments

Comments
 (0)