Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

add comments to explain 403 responses

Jean-Baptiste Kaiser66ccc452d247
diff --git a/supabase/functions/postmark/addNoteToContact.ts b/supabase/functions/postmark/addNoteToContact.ts
index 8929e910..4401b196 100644
--- a/supabase/functions/postmark/addNoteToContact.ts
+++ b/supabase/functions/postmark/addNoteToContact.ts
@@ -25,11 +25,14 @@ export const addNoteToContact = async ({
`Could not fetch sales from database, email: ${salesEmail}`,
{ status: 500 }
);
- if (!sales)
+ if (!sales) {
+ // Return a 403 to let Postmark know that it's no use to retry this request
+ // https://postmarkapp.com/developer/webhooks/inbound-webhook#errors-and-retries
return new Response(
`Unable to find sales in database, email: ${salesEmail}`,
{ status: 403 }
);
+ }
// Check if the contact already exists
const { data: existingContact, error: fetchContactError } =
diff --git a/supabase/functions/postmark/index.ts b/supabase/functions/postmark/index.ts
index 489e2148..a95fd514 100644
--- a/supabase/functions/postmark/index.ts
+++ b/supabase/functions/postmark/index.ts
@@ -37,18 +37,24 @@ Deno.serve(async req => {
const noteContent = getNoteContent(Subject, StrippedTextReply || TextBody);
const { Email: salesEmail } = FromFull;
- if (!salesEmail)
+ if (!salesEmail) {
+ // Return a 403 to let Postmark know that it's no use to retry this request
+ // https://postmarkapp.com/developer/webhooks/inbound-webhook#errors-and-retries
return new Response(
`Could not extract sales email from FromFull: ${FromFull}`,
{ status: 403 }
);
+ }
const { firstName, lastName, email, domain } =
extractMailContactData(ToFull);
- if (!email)
+ if (!email) {
+ // Return a 403 to let Postmark know that it's no use to retry this request
+ // https://postmarkapp.com/developer/webhooks/inbound-webhook#errors-and-retries
return new Response(`Could not extract email from ToFull: ${ToFull}`, {
status: 403,
});
+ }
return await addNoteToContact({
salesEmail,
@@ -94,6 +100,9 @@ const checkRequestTypeAndHeaders = (req: Request) => {
const checkBody = (json: any) => {
const { ToFull, FromFull, Subject, TextBody } = json;
+ // In case of incorrect request data, we
+ // return a 403 to let Postmark know that it's no use to retry this request
+ // https://postmarkapp.com/developer/webhooks/inbound-webhook#errors-and-retries
if (!ToFull || !ToFull.length)
return new Response('Missing parameter: ToFull', { status: 403 });
if (!FromFull)