mirror of
https://github.com/theodore-song/polymarket-analyst.git
synced 2026-08-24 04:58:08 +00:00
Harden database state failover diagnostics
This commit is contained in:
+2
-3
@@ -19,9 +19,8 @@ export function normalizeDatabaseUrl(raw) {
|
||||
export function databaseUrls() {
|
||||
const candidates = [process.env.DATABASE_URL, process.env.NEON_DATABASE_URL]
|
||||
.map(normalizeDatabaseUrl).filter(Boolean);
|
||||
const ordered = [...candidates.filter(value => /^postgres(?:ql)?:\/\//i.test(value)),
|
||||
...candidates.filter(value => !/^postgres(?:ql)?:\/\//i.test(value))];
|
||||
return [...new Set(ordered)];
|
||||
const valid = candidates.filter(value => /^postgres(?:ql)?:\/\//i.test(value));
|
||||
return [...new Set(valid.length ? valid : candidates)];
|
||||
}
|
||||
|
||||
export function databaseUrl() {
|
||||
|
||||
@@ -19,7 +19,13 @@ function withBlobAuth(options = {}) {
|
||||
|
||||
export function providerErrorCode(error) {
|
||||
if (!error) return "not_configured_or_not_attempted";
|
||||
const code = String(error.code || error.cause && error.cause.code || "").toUpperCase();
|
||||
const message = String(error.message || error).toLowerCase();
|
||||
if (code === "28P01" || code === "28000") return "authorization_failed";
|
||||
if (code === "3D000") return "database_not_found";
|
||||
if (code.startsWith("08")) return "connection_failed";
|
||||
if (code === "ENOTFOUND" || code === "EAI_AGAIN") return "dns_failed";
|
||||
if (code === "ETIMEDOUT" || code === "UND_ERR_CONNECT_TIMEOUT") return "timeout";
|
||||
if (message.includes("invalid") && (message.includes("url") || message.includes("connection string"))) return "invalid_connection_string";
|
||||
if (message.includes("password authentication") || message.includes("unauthorized") || /\b(?:401|403)\b/.test(message)) return "authorization_failed";
|
||||
if (message.includes("enotfound") || message.includes("getaddrinfo") || message.includes("dns")) return "dns_failed";
|
||||
|
||||
Reference in New Issue
Block a user