mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
* Adds `not_found` hook * Separate hooks and endpoints initialization process * Adds additional application events * Remove unused import * Change the event order to accound for notFound and errorHandler * Change emitAsync.catch to use the emitAsyncSafe function * Updated docs, reordered table by lifecycle and usage
22 lines
563 B
TypeScript
22 lines
563 B
TypeScript
import { EventEmitter2 } from 'eventemitter2';
|
|
import logger from './logger';
|
|
|
|
const emitter = new EventEmitter2({ wildcard: true, verboseMemoryLeak: true, delimiter: '.' });
|
|
|
|
/**
|
|
* Emit async events without throwing errors. Just log them out as warnings.
|
|
* @param name
|
|
* @param args
|
|
*/
|
|
export async function emitAsyncSafe(name: string, ...args: any[]) {
|
|
try {
|
|
return await emitter.emitAsync(name, ...args);
|
|
} catch (err) {
|
|
logger.warn(`An error was thrown while executing hook "${name}"`);
|
|
logger.warn(err);
|
|
}
|
|
return [];
|
|
}
|
|
|
|
export default emitter;
|