Skip to content

Commit c6ef8f3

Browse files
authored
Merge pull request #2647 from ankaboot-source/docs/update-readme-features
fix(campaigns): improve error messages for OAuth issues
2 parents 7d55d0f + 828b77f commit c6ef8f3

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

supabase/functions/email-campaigns/index.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,44 @@ function extractErrorMessage(error: unknown): string {
287287
return "Unknown error";
288288
}
289289

290+
function getUserFriendlyError(error: unknown): string {
291+
const message = extractErrorMessage(error);
292+
293+
// Detect OAuth/credential errors (535, 534, BadCredentials, etc.)
294+
if (
295+
message.includes("535") ||
296+
message.includes("534") ||
297+
message.includes("BadCredentials") ||
298+
message.includes("invalid credentials") ||
299+
message.includes("authentication") ||
300+
message.includes("Username and Password not accepted")
301+
) {
302+
return "Identifiants OAuth invalides ou token expiré. Veuillez reconnecter ce compte.";
303+
}
304+
305+
// Detect connection/timeout errors
306+
if (
307+
message.includes("ETIMEDOUT") ||
308+
message.includes("timeout") ||
309+
message.includes("ECONNREFUSED") ||
310+
message.includes("ENOTFOUND")
311+
) {
312+
return "Impossible de se connecter au serveur SMTP. Veuillez réessayer plus tard.";
313+
}
314+
315+
// Detect rate limiting
316+
if (
317+
message.includes("rate limit") ||
318+
message.includes("throttl") ||
319+
message.includes("429")
320+
) {
321+
return "Trop de requêtes. Veuillez réessayer plus tard.";
322+
}
323+
324+
// Default: return the original message but truncated
325+
return message.length > 100 ? message.substring(0, 100) + "..." : message;
326+
}
327+
290328
function toTextFromHtml(html: string): string {
291329
return html
292330
.replace(/<br\s*\/?>/gi, "\n")
@@ -646,7 +684,7 @@ async function resolveSenderOptions(authorization: string, userEmail: string) {
646684
options.push({
647685
email: source.email,
648686
available: false,
649-
reason: extractErrorMessage(error),
687+
reason: getUserFriendlyError(error),
650688
});
651689
}
652690
}

supabase/functions/email-campaigns/sender-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function getSenderCredentialIssue(
171171

172172
const expiresAt = Number(source.credentials.expiresAt);
173173
if (Number.isFinite(expiresAt) && expiresAt > 0 && expiresAt <= nowMs) {
174-
return "OAuth token expired. Reconnect this source.";
174+
return "Token OAuth expiré. Veuillez reconnecter ce compte dans les sources.";
175175
}
176176

177177
return null;

0 commit comments

Comments
 (0)