Skip to content

Commit c0b7056

Browse files
make it fail if it can't retreive the json on load
1 parent fedc460 commit c0b7056

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ appveyor.yml
77
Gruntfile.js
88
tasks
99
test
10+
src

src/registry/domain/components-cache/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import getComponentsList from './components-list';
33
import eventsHandler from '../events-handler';
44
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
55
import { ComponentsList, Config } from '../../../types';
6-
import { StorageAdapter } from 'oc-storage-adapters-utils';
6+
import { StorageAdapter, strings } from 'oc-storage-adapters-utils';
77

88
export default function componentsCache(conf: Config, cdn: StorageAdapter) {
99
let cachedComponentsList: ComponentsList;
@@ -56,9 +56,12 @@ export default function componentsCache(conf: Config, cdn: StorageAdapter) {
5656
},
5757

5858
async load(): Promise<ComponentsList> {
59-
const jsonComponents = await componentsList
60-
.getFromJson()
61-
.catch(() => null);
59+
const jsonComponents = await componentsList.getFromJson().catch(err => {
60+
if (err?.code === strings.errors.STORAGE.FILE_NOT_FOUND_CODE)
61+
return null;
62+
63+
return Promise.reject(err);
64+
});
6265
const dirComponents = await componentsList
6366
.getFromDirectories(jsonComponents)
6467
.catch(err => throwError('components_list_get', err));

test/unit/registry-domain-components-cache.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,27 @@ describe('registry : domain : components-cache', () => {
5959
};
6060

6161
describe('when library does not contain components.json', () => {
62+
describe('when getting the json fails', () => {
63+
let error;
64+
before(done => {
65+
mockedCdn.getJson = sinon.stub();
66+
mockedCdn.getJson.rejects('FILE_ERROR');
67+
initialise();
68+
componentsCache
69+
.load()
70+
.catch(err => (error = err))
71+
.finally(done);
72+
});
73+
74+
it('should throw with the error message', () => {
75+
expect(error).to.equal('FILE_ERROR');
76+
});
77+
});
6278
describe('when initialising the cache', () => {
6379
before(done => {
6480
mockedCdn.getJson = sinon.stub();
6581
mockedCdn.getJson.resolves({});
66-
mockedCdn.getJson.onFirstCall(0).rejects('not_found');
82+
mockedCdn.getJson.onFirstCall(0).rejects({ code: 'file_not_found' });
6783
mockedCdn.listSubDirectories = sinon.stub();
6884
mockedCdn.listSubDirectories.onCall(0).resolves(['hello-world']);
6985
mockedCdn.listSubDirectories.onCall(1).resolves(['1.0.0', '1.0.2']);

0 commit comments

Comments
 (0)