From 1e82e0a8cda396cdd36a20a8a0ebc534978c9199 Mon Sep 17 00:00:00 2001 From: Noisekit Date: Fri, 6 Dec 2024 14:18:29 +1100 Subject: [PATCH] Add error handling --- src/server.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/server.js b/src/server.js index 56ec064..a967f45 100644 --- a/src/server.js +++ b/src/server.js @@ -126,8 +126,8 @@ redisClient.on('ready', () => { const v3MainnetScPoolAPYAllRouter = require('./routes/v3/mainnet/sc-pool-apy-all.js'); app.use('/v3/mainnet/sc-pool-apy-all', v3MainnetScPoolAPYAllRouter); -// const v3SnaxTestnetVotesRouter = require('./routes/v3/snax-testnet/votes.js'); -// app.use('/v3/snax-testnet/votes', v3SnaxTestnetVotesRouter); + // const v3SnaxTestnetVotesRouter = require('./routes/v3/snax-testnet/votes.js'); + // app.use('/v3/snax-testnet/votes', v3SnaxTestnetVotesRouter); const v3SnaxVotesRouter = require('./routes/v3/snax/votes.js'); app.use('/v3/snax/votes', v3SnaxVotesRouter); @@ -142,6 +142,15 @@ redisClient.on('ready', () => { const statsPerpsVolumeRouter = require('./routes/stats/perps-volume.js'); app.use('/stats/perps-volume', statsPerpsVolumeRouter); + app.use(function errorHandler(err, req, res, next) { + console.error(err); + if (res.headersSent) { + return next(err); + } + res.status(500); + res.json({ error: err.message }); + }); + log.debug('[Express] Starting server..'); const port = typeof process.env.API_PORT === 'string'