This commit is contained in:
Sergey Yarkov 2026-03-10 16:26:42 +03:00
parent 611a42a249
commit ad361727b1
2 changed files with 16 additions and 2 deletions

View File

@ -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
});
}
}

View File

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