mirror of
https://github.com/directus/directus.git
synced 2026-02-16 23:21:51 -05:00
Rework hook registration (#8027)
* Rework hook registration * Remove event and action fields from hook payloads * Move "error" action to "request.error" filter * Emit meta and context objects in filters and actions * Run filters sequentially * Update hook templates * Fix CLI hook test * Also emit `<collection>.items.crud` when emitting `items.crud`. * Update hook docs Co-authored-by: Oreilles <oreilles.github@nitoref.io> Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
committed by
GitHub
parent
0aa5026aa9
commit
3d0e086c55
@@ -1,10 +1,11 @@
|
||||
import { ErrorRequestHandler } from 'express';
|
||||
import { emitAsyncSafe } from '../emitter';
|
||||
import emitter from '../emitter';
|
||||
import env from '../env';
|
||||
import { MethodNotAllowedException } from '../exceptions';
|
||||
import { BaseException } from '@directus/shared/exceptions';
|
||||
import logger from '../logger';
|
||||
import { toArray } from '@directus/shared/utils';
|
||||
import getDatabase from '../database';
|
||||
|
||||
// Note: keep all 4 parameters here. That's how Express recognizes it's the error handler, even if
|
||||
// we don't use next
|
||||
@@ -87,9 +88,20 @@ const errorHandler: ErrorRequestHandler = (err, req, res, _next) => {
|
||||
}
|
||||
}
|
||||
|
||||
emitAsyncSafe('error', payload.errors).then(() => {
|
||||
return res.json(payload);
|
||||
});
|
||||
emitter
|
||||
.emitFilter(
|
||||
'request.error',
|
||||
payload.errors,
|
||||
{},
|
||||
{
|
||||
database: getDatabase(),
|
||||
schema: req.schema,
|
||||
accountability: req.accountability ?? null,
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
return res.json(payload);
|
||||
});
|
||||
};
|
||||
|
||||
export default errorHandler;
|
||||
|
||||
Reference in New Issue
Block a user