From ad361727b134b95ad1e00323f2829f6310de0182 Mon Sep 17 00:00:00 2001 From: sergeyyarkov Date: Tue, 10 Mar 2026 16:26:42 +0300 Subject: [PATCH] refactor --- http-server/errors.js | 13 +++++++++++++ http-server/route.js | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/http-server/errors.js b/http-server/errors.js index 0627431..5fc92b0 100644 --- a/http-server/errors.js +++ b/http-server/errors.js @@ -61,3 +61,16 @@ export class ServiceUnavailableError extends HttpError { }); } } + +export class EntityTooLargeError extends HttpError { + /** + * @param {string} [message] + */ + constructor(message) { + super({ + name: "ERR_ENTITY_TOO_LARGE", + message: message || "Entity too large", + statusCode: 413 + }); + } +} diff --git a/http-server/route.js b/http-server/route.js index 5c959f2..7c43d44 100644 --- a/http-server/route.js +++ b/http-server/route.js @@ -15,6 +15,7 @@ export function createRouter() { return { async handle(ctx) { const { req, res } = ctx; + const headers = req.req.headers; try { for (const route of routes) { @@ -28,11 +29,11 @@ export function createRouter() { ctx.params = patternResult.pathname.groups; - if (req.req.headers["content-type"]?.includes("application/json")) { + if (headers["content-type"]?.includes("application/json")) { ctx.data = await ctx.req.parseJson(); } - if (req.req.headers["content-type"]?.includes("multipart/form-data")) { + if (headers["content-type"]?.includes("multipart/form-data")) { if (!route.options.incomingForm) { throw new BadRequestError("Request cannot be processed without defined incoming form."); }