directus
40 строк · 937.0 Байт
1import type { RequestHandler } from 'express';2import getDatabase from '../database/index.js';3import emitter from '../emitter.js';4import { RouteNotFoundError } from '@directus/errors';5
6/**
7* Handles not found routes.
8*
9* - If a hook throws an error, the error gets forwarded to the error handler.
10* - If a hook returns true, the handler assumes the response has been
11* processed and won't generate a response.
12*
13* @param req
14* @param res
15* @param next
16*/
17const notFound: RequestHandler = async (req, res, next) => {18try {19const hooksResult = await emitter.emitFilter(20'request.not_found',21false,22{ request: req, response: res },23{24database: getDatabase(),25schema: req.schema,26accountability: req.accountability ?? null,27},28);29
30if (hooksResult) {31return next();32}33
34next(new RouteNotFoundError({ path: req.path }));35} catch (err: any) {36next(err);37}38};39
40export default notFound;41