Currently next-connect has onError option to catch errors thrown by handlers and send relevant response. But it doesn't work with async handlers.
What I would like to have is error thrown from a async handler should get caught in onError without have to write try/catch blocks and then pass the error to next(Error) function.
import nextConnect from 'next-connect';
handler = nextConnect({ onError });
handler.use(async (req, res) => {
throw new Error("Something failed");
});
Currently
next-connect
hasonError
option to catch errors thrown by handlers and send relevant response. But it doesn't work withasync
handlers. What I would like to have is error thrown from a async handler should get caught inonError
without have to writetry/catch
blocks and then pass the error tonext(Error)
function.