mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
improvement: move sentry config to .env
This commit is contained in:
@@ -6,7 +6,6 @@ const Youch = require("youch");
|
||||
const cors = require("cors");
|
||||
const multer = require("multer");
|
||||
const Sentry = require("@sentry/node");
|
||||
const sentryConfig = require("./config/sentry");
|
||||
|
||||
const wBot = require("./libs/wbot");
|
||||
const wbotMessageListener = require("./services/wbotMessageListener");
|
||||
@@ -24,7 +23,7 @@ const server = app.listen(process.env.PORT, () => {
|
||||
console.log(`Server started on port: ${process.env.PORT}`);
|
||||
});
|
||||
|
||||
Sentry.init(sentryConfig);
|
||||
Sentry.init({ dsn: process.env.SENTRY_DSN });
|
||||
|
||||
const fileStorage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
@@ -46,17 +45,6 @@ app.use(ContactsRoutes);
|
||||
app.use(TicketsRoutes);
|
||||
app.use(MessagesRoutes);
|
||||
app.use(WhatsRoutes);
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
app.use(async (err, req, res, next) => {
|
||||
if (process.env.NODE_ENV === "DEVELOPMENT") {
|
||||
const errors = await new Youch(err, req).toJSON();
|
||||
console.log(err);
|
||||
return res.status(500).json(errors);
|
||||
}
|
||||
console.log(err);
|
||||
return res.status(500).json({ error: "Internal server error" });
|
||||
});
|
||||
|
||||
const io = require("./libs/socket").init(server);
|
||||
io.on("connection", socket => {
|
||||
@@ -83,3 +71,15 @@ wBot
|
||||
wbotMonitor();
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
app.use(async (err, req, res, next) => {
|
||||
if (process.env.NODE_ENV === "DEVELOPMENT") {
|
||||
const errors = await new Youch(err, req).toJSON();
|
||||
console.log(err);
|
||||
return res.status(500).json(errors);
|
||||
}
|
||||
console.log(err);
|
||||
return res.status(500).json({ error: "Internal server error" });
|
||||
});
|
||||
|
||||
@@ -87,7 +87,7 @@ exports.index = async (req, res) => {
|
||||
};
|
||||
}
|
||||
|
||||
const { count, rows: tickets } = await Ticket.findAndCountAll({
|
||||
const { count, rows: tickets } = await Ticket.findAndCoundtAll({
|
||||
where: whereCondition,
|
||||
distinct: true,
|
||||
include: includeCondition,
|
||||
|
||||
@@ -2,6 +2,7 @@ const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { Op } = require("sequelize");
|
||||
const { subHours } = require("date-fns");
|
||||
const Sentry = require("@sentry/node");
|
||||
|
||||
const Contact = require("../models/Contact");
|
||||
const Ticket = require("../models/Ticket");
|
||||
@@ -149,6 +150,7 @@ const wbotMessageListener = () => {
|
||||
|
||||
await handleMessage(msg, ticket, contact);
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
@@ -171,6 +173,7 @@ const wbotMessageListener = () => {
|
||||
message: messageToUpdate,
|
||||
});
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const Sentry = require("@sentry/node");
|
||||
|
||||
const Whatsapp = require("../models/Whatsapp");
|
||||
const wbotMessageListener = require("./wbotMessageListener");
|
||||
|
||||
@@ -19,6 +21,7 @@ const wbotMonitor = () => {
|
||||
try {
|
||||
await Whatsapp.update({ battery, plugged }, { where: { id: 1 } });
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
@@ -34,7 +37,10 @@ const wbotMonitor = () => {
|
||||
wbotMessageListener();
|
||||
wbotMonitor();
|
||||
})
|
||||
.catch(err => console.log(err)),
|
||||
.catch(err => {
|
||||
Sentry.captureException(err);
|
||||
console.log(err);
|
||||
}),
|
||||
2000
|
||||
);
|
||||
});
|
||||
@@ -43,6 +49,7 @@ const wbotMonitor = () => {
|
||||
// wbot.resetState();
|
||||
// }, 20000);
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user