Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2926,11 +2926,12 @@ All errors return JSON with an \`error\` field and optional \`code\`:
}

v1Router.post("/profiles/:username/webhooks", requireAuth, async (req, res) => {
const parsed = webhookCreateSchema.safeParse(req.body);
if (!parsed.success) return sendError(res, 400, "Invalid URL — must be a valid HTTPS URL");
try {
const parsed = webhookCreateSchema.safeParse(req.body);
if (!parsed.success) return sendError(res, 400, "Invalid URL — must be a valid HTTPS URL");

const profile = await resolveProfileOwner(req.params.username as string, req.auth, res);
if (!profile) return;
const profile = await resolveProfileOwner(req.params.username as string, req.auth, res);
if (!profile) return;

try {
const result = await prisma.$transaction(
Expand Down Expand Up @@ -3421,7 +3422,9 @@ All errors return JSON with an \`error\` field and optional \`code\`:
existingTxHash,
});
}
throw error;
// Handle other database errors gracefully instead of crashing the process
req.log.error({ err: error, txHash: parsed.data.txHash }, "Database error recording support transaction");
return sendError(res, 500, "Internal server error");
}

// Notify creator (async, best-effort) — respects NotificationPreferences
Expand Down
11 changes: 8 additions & 3 deletions backend/src/verify-transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ async function suiteExponentialBackoff() {
assert.strictEqual(attempt, 3, "Should retry twice before succeeding");
});

await test("returns 'error' after exhausting all retries", async () => {
await test("throws after exhausting all retries", async () => {
let attempt = 0;
const server = {
transactions: () => ({
Expand All @@ -419,8 +419,13 @@ async function suiteExponentialBackoff() {
}),
} as unknown as Horizon.Server;

const result = await verifyTransaction(server, "exhaust-hash", 3, 10);
assert.strictEqual(result, "error");
await assert.rejects(
async () => verifyTransaction(server, "exhaust-hash", 3, 10),
(err: any) => {
assert.ok(err instanceof Error, "Should throw an Error");
return true;
}
);
assert.strictEqual(attempt, 3, "Should attempt exactly 3 times");
});

Expand Down