feat: change invoke CMS Events to throw Error (#5813)
This commit is contained in:
parent
089533683b
commit
90bf4cb06a
@ -170,6 +170,19 @@ describe('registry', () => {
|
|||||||
expect(handler).toHaveBeenCalledTimes(2);
|
expect(handler).toHaveBeenCalledTimes(2);
|
||||||
expect(handler).toHaveBeenLastCalledWith(data, options2);
|
expect(handler).toHaveBeenLastCalledWith(data, options2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should throw error when '${name}' handler throws error`, async () => {
|
||||||
|
const { registerEventListener, invokeEvent } = require('../registry');
|
||||||
|
|
||||||
|
const handler = jest.fn(() => {
|
||||||
|
throw new Error('handler failed!');
|
||||||
|
});
|
||||||
|
|
||||||
|
registerEventListener({ name, handler });
|
||||||
|
const data = { entry: fromJS({ data: {} }) };
|
||||||
|
|
||||||
|
await expect(invokeEvent({ name, data })).rejects.toThrow('handler failed!');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return an updated entry's DataMap`, async () => {
|
it(`should return an updated entry's DataMap`, async () => {
|
||||||
|
@ -246,15 +246,11 @@ export async function invokeEvent({ name, data }) {
|
|||||||
|
|
||||||
let _data = { ...data };
|
let _data = { ...data };
|
||||||
for (const { handler, options } of handlers) {
|
for (const { handler, options } of handlers) {
|
||||||
try {
|
|
||||||
const result = await handler(_data, options);
|
const result = await handler(_data, options);
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
const entry = _data.entry.set('data', result);
|
const entry = _data.entry.set('data', result);
|
||||||
_data = { ...data, entry };
|
_data = { ...data, entry };
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.warn(`Failed running handler for event ${name} with message: ${e.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return _data.entry.get('data');
|
return _data.entry.get('data');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user