Created
September 12, 2023 02:50
-
-
Save rodrigorodriguescosta/b81b3bbcd28fa35c06ddeb805b4685f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const originalGet = app.get; | |
app.get = (route, ...handlers) => { | |
const wrappedHandlers = handlers.map(handler => { | |
return async (req, res, next) => { | |
try { | |
await handler(req, res, next); | |
} catch (err) { | |
console.error('eita nois deu ruim:', err); | |
next(err); | |
} | |
}; | |
}); | |
originalGet.call(app, route, ...wrappedHandlers); | |
}; | |
app.get('/', (req, res) => { | |
throw new Error('algo deu errado'); | |
}); | |
app.get('/teste', (req, res) => { | |
res.send('opaaaa'); | |
}); | |
app.listen(3000, () => { | |
console.log('rodando 3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment