Integrations

Express

If the application uses Express, initiate and configure Djaty then use our Djaty Request and Error middleware. Noting that Djaty request middleware should be the first middleware used and Djaty error middleware should be the last middleware used.

const app = express();
djaty.init({
  apiKey: 'API_KEY',
  apiSecret: 'API_SECRET',
});

// First middleware to be used should be `djaty.requestHandler()`
app.use(djaty.requestHandler());

// ... Using all other application middleware

// Last middleware to be used should be `djaty.errorHandler()`
app.use(djaty.errorHandler());

Koa

If the application uses Koa, initiate and configure Djaty then use our Djaty Request and Error middlewares. Noting that Djaty request middleware should be the first middleware used and Djaty error middleware should catch its thrown errors.

const {djaty} = require('@djaty/djaty-nodejs');
djaty.init({
  apiKey: 'API_KEY',
  apiSecret: 'API_SECRET',
});

const app = module.exports = new koa();

// Add Djaty as your first middleware
app.use((ctx, next) => djaty.requestHandler()(ctx.req, ctx.res, next)
  .catch(err => djaty.errorHandler()(err, ctx.req, ctx.res)));

// Other middleware...

app.on('error', (err) => {
  djaty.trackBug(err);
});

Loopback

If the application uses Loopback, initiate and configure Djaty then use our Djaty Request and Error middleware. Noting that Djaty request middleware should be registered with initial:before and Djaty error middleware should be registered final:after.

Editserver.js file to include the following:

const {djaty} = require('@djaty/djaty-nodejs');
djaty.init({
  apiKey: 'API_KEY',
  apiSecret: 'API_SECRET',
});

const app = module.exports = loopback();
app.middleware('initial:before', djaty.requestHandler());
app.middleware('final:after', djaty.errorHandler());