grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.17k stars 110 forks source link

Error handling in web hook mode #530

Closed eedea closed 4 months ago

eedea commented 6 months ago

I have a bot working in webhook mode and I want to use express for error handling I have written a simple middleware for it but it looks like it doesn't receive error from bot since it throw error in bot and the app crashes. Is there anything I have to do in bot section of code?

app.use((err, req, res, next) => {
    console.log(err.stack);
    res.status(500).send("Something broke!");
    next();
  });
KnorpelSenf commented 6 months ago

Do you use express v4? It does not support promises yet, so if your grammY middleware rejects, express does not catch it. You need to wrap it inside a custom error handler and convert the error to the express callbacks. My personal suggestion is to either ditch express entirely, or use grammY error boundaries so you can catch errors before they even reach express.

KnorpelSenf commented 4 months ago

Closing due to inactivity