Update Question: error: TypeError: res.json is not a function
I use Firebase Cloud Functions with Express app. I use middleware for handle error, but it is not working. How to catch/handle error when using throw new Error()?
My code below:
app.get('/test', (req, res) => { throw new Error('this is error') }) function errorHandler(err, req, res, next) { res.json({error: err.message}) // error here } app.use(errorHandler) exports.api = functions.https.onRequest(app) Please help me. Thanks very much.