multipart
This commit is contained in:
@@ -65,7 +65,7 @@ async function createApi() {
|
||||
next();
|
||||
});
|
||||
app.use(corsMiddleware);
|
||||
app.use(express.json());
|
||||
app.use(express.json({ limit: env.bodyLimit }));
|
||||
app.use(cookieParser());
|
||||
app.use(loggerMiddleware);
|
||||
app.use(authMiddleware);
|
||||
@@ -79,6 +79,16 @@ async function createApi() {
|
||||
|
||||
await loadRoutes(app, '/api');
|
||||
|
||||
app.use((err, _req, res, next) => {
|
||||
if (err.type === 'entity.too.large') {
|
||||
return res.status(413).json({ error: 'Payload too large' });
|
||||
}
|
||||
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
|
||||
return res.status(400).json({ error: 'Invalid JSON body' });
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user