const router = require('express').Router(); const response = require('./responseDecorator'); // const config = require('../../config-handler'); // Подгрузка с файла function catchError (func) { func(); } router.use('/:method_name', async (req, res, next, ...etc) => { try { const methodFunct = require(`./methods/${req.params.method_name}`); response(methodFunct, req, res); } catch (e) { try { console.log(e); const ApiError = require('./errorClass'); catchError( () => res.status(400).send(response((req, res) => { throw new ApiError("METHOD_NOT_FOUNDED"); }, req, res)) ); } catch (_e) {} // Посылаем 'Cannot set headers after they are sent to the client' в.. обработку.. без обработчика. } }); module.exports = router;