Obafunso Ridwan

Error Handling

Express.js 🕷️

Suya extends the global Error class. Some errors could be handle through express middleware.

  // global express error handler
  app.use((err, req, res, next) => {
    if (err.name == 'SuyaError') {
      return res.status(500).json({
          success: false,
          error: {
              message: err.message,
          },
      })
    }
  })

[Important Notice]: Some errors occur during the initializations of suya object and these errors are thrown when developers don’t follow typescript compiler/rules according to suya types definition. These errors are been underlined during the development but the developer ignores them.

⏮️ Usage | Tests ⏭️