From 4c405911d05363b4da3782a4ec159c13270d0ae5 Mon Sep 17 00:00:00 2001 From: Jack MB Date: Thu, 20 Jun 2024 13:50:59 +0200 Subject: [PATCH] move email errors to error channel on slack --- lib/resend/email.ts | 6 ++++-- lib/slack.ts | 12 ++++++++---- pages/api/admin/artwork-email.ts | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/resend/email.ts b/lib/resend/email.ts index 04f7a9fb..abc451b4 100644 --- a/lib/resend/email.ts +++ b/lib/resend/email.ts @@ -74,7 +74,8 @@ export async function sendConfirmationEmail(show) { // send message to slack saying there was an issue sending the email console.log(error); sendSlackMessage( - `Failed to send email request to ${artist.name}(${artist.email}) on show *${show.title}*. ${error.name} - ${error.message}. <@U04HG3VHHEW>` + `Failed to send email request to ${artist.name}(${artist.email}) on show *${show.title}*. ${error.name} - ${error.message}. <@U04HG3VHHEW>`, + "error" ); } } @@ -109,7 +110,8 @@ export async function sendArtworkEmail(artist, date) { // send message to slack saying there was an issue sending the email console.log(error); sendSlackMessage( - `Failed to send artwork email to ${artist.name}(${artist.email}). ${error.name} - ${error.message}. <@U04HG3VHHEW>` + `Failed to send artwork email to ${artist.name}(${artist.email}). ${error.name} - ${error.message}. <@U04HG3VHHEW>`, + "error" ); } } diff --git a/lib/slack.ts b/lib/slack.ts index 44a2e14c..5d2badcf 100644 --- a/lib/slack.ts +++ b/lib/slack.ts @@ -1,11 +1,15 @@ const slackURL = process.env.SLACK_WEBHOOK_URL; const slackDevURL = process.env.SLACK_DEV_WEBHOOK_URL; +const slackErrorURL = process.env.SLACK_ERROR_WEBHOOK_URL; export function sendSlackMessage(text: string, channel?: string) { - let url = slackURL; - if (channel && channel == "dev") { - url = slackDevURL; - } + const urlMap = { + error: slackErrorURL, + dev: slackDevURL, + }; + + const url = urlMap[channel] || slackURL; + fetch(url, { method: "POST", body: JSON.stringify({ diff --git a/pages/api/admin/artwork-email.ts b/pages/api/admin/artwork-email.ts index 169223b7..7394480c 100644 --- a/pages/api/admin/artwork-email.ts +++ b/pages/api/admin/artwork-email.ts @@ -42,7 +42,8 @@ export default async function handler( error ); await sendSlackMessage( - `Failed to send email request to ${artist.name} (${artist.email}) for show *${show.title}*. Error: ${error.message}. <@U04HG3VHHEW>` + `Failed to send email request to ${artist.name} (${artist.email}) for show *${show.title}*. Error: ${error.message}. <@U04HG3VHHEW>`, + "error" ); } }