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."); }