mirror of
https://github.com/sergeyyarkov/asu_tools_service.git
synced 2026-10-11 10:29:22 +03:00
refactor
This commit is contained in:
parent
611a42a249
commit
ad361727b1
@ -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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ export function createRouter() {
|
|||||||
return {
|
return {
|
||||||
async handle(ctx) {
|
async handle(ctx) {
|
||||||
const { req, res } = ctx;
|
const { req, res } = ctx;
|
||||||
|
const headers = req.req.headers;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const route of routes) {
|
for (const route of routes) {
|
||||||
@ -28,11 +29,11 @@ export function createRouter() {
|
|||||||
|
|
||||||
ctx.params = patternResult.pathname.groups;
|
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();
|
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) {
|
if (!route.options.incomingForm) {
|
||||||
throw new BadRequestError("Request cannot be processed without defined incoming form.");
|
throw new BadRequestError("Request cannot be processed without defined incoming form.");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user