directus

Форк
0
/
not-found.ts 
40 строк · 937.0 Байт
1
import type { RequestHandler } from 'express';
2
import getDatabase from '../database/index.js';
3
import emitter from '../emitter.js';
4
import { 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
 */
17
const notFound: RequestHandler = async (req, res, next) => {
18
	try {
19
		const hooksResult = await emitter.emitFilter(
20
			'request.not_found',
21
			false,
22
			{ request: req, response: res },
23
			{
24
				database: getDatabase(),
25
				schema: req.schema,
26
				accountability: req.accountability ?? null,
27
			},
28
		);
29

30
		if (hooksResult) {
31
			return next();
32
		}
33

34
		next(new RouteNotFoundError({ path: req.path }));
35
	} catch (err: any) {
36
		next(err);
37
	}
38
};
39

40
export default notFound;
41

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.