refactor(discord notify): move to utlis so we can use it in other places outside the logger
This commit is contained in:
45
app/src/pkg/utils/notify.ts
Normal file
45
app/src/pkg/utils/notify.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { Log } from "../db/schema/logs.js";
|
||||
import { validateEnv } from "../utils/envValidator.js";
|
||||
|
||||
const env = validateEnv(process.env);
|
||||
|
||||
export async function sendNotify(log: any) {
|
||||
const webhookUrl = process.env.WEBHOOK_URL!;
|
||||
let payload = {
|
||||
embeds: [
|
||||
{
|
||||
title: `🚨 ${env.PROD_PLANT_TOKEN}: encounter a critical error `,
|
||||
description: `Where was the error: ${log.module}${
|
||||
log.subModule ? `-${log.subModule}` : ""
|
||||
}`,
|
||||
color: 0xff0000, // red
|
||||
fields: [
|
||||
{
|
||||
name: "Message",
|
||||
value: log.message,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Hostname",
|
||||
value: log.hostname,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Stack",
|
||||
value: "```" + (log.stack ?? "no stack") + "```",
|
||||
},
|
||||
],
|
||||
footer: {
|
||||
text: "LST Logger 💀",
|
||||
},
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await fetch(webhookUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user