Skip to content

Commit d77e06d

Browse files
committed
add error handling
1 parent 921a094 commit d77e06d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

app.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app } from 'mu';
1+
import { app, errorHandler } from 'mu';
22
import services from './config/rules';
33
import normalizeQuad from './config/normalize-quad';
44
import bodyParser from 'body-parser';
@@ -68,6 +68,19 @@ app.post( '/', bodyParser.json({limit: '500mb'}), function( req, res ) {
6868
res.status(204).send();
6969
} );
7070

71+
// log delta's ignored because of size
72+
app.use((err, req, res, next) => {
73+
if (err.type === 'entity.too.large') {
74+
console.warn(`Payload too large for ${req.method} ${req.originalUrl}`);
75+
return res.status(413).send('Payload too large');
76+
}
77+
78+
// Pass other errors to the default handler
79+
next(err);
80+
});
81+
82+
app.use(errorHandler);
83+
7184
async function informWatchers( changeSets, res, muCallIdTrail, muSessionId ){
7285
// Iterate over each unique match pattern
7386
for (const matchKey in groupedServices) {

0 commit comments

Comments
 (0)