Click redirect preserves original URL on tracking failure
Why it matters
Click redirect handlers sit in the path between every tracked link in your emails and the page the recipient is trying to reach. When tracking logic throws an unhandled exception — a database timeout, a network blip, a missing link ID — and the redirect doesn't fire, the user hits a 500 error instead of your landing page. Every tracked link in every sent email becomes a broken link for the duration of the outage. This is an iso-25010:2011 reliability failure: the observability instrumentation should never degrade the user's ability to navigate to the destination URL.
Severity rationale
High because a tracking write failure converts every email link into a broken link for the user, destroying the campaign's conversion path and damaging sender reputation in a way that affects every recipient simultaneously.
Remediation
Wrap all tracking logic in a try/catch and fire the tracking write as a detached promise so a DB failure never blocks the redirect. Set a safe fallback URL before the try block:
export async function GET(req: Request, { params }: { params: { token: string } }) {
let destinationUrl = 'https://yourdomain.com' // fallback — never leave this blank
try {
const link = await db.trackedLinks.findUnique({ where: { token: params.token } })
if (link) {
destinationUrl = link.original_url
// Fire-and-forget — do not await in the redirect path
db.clickEvents.create({
data: { link_id: link.id, campaign_id: link.campaign_id, occurred_at: new Date() }
}).catch((err) => console.error('Click tracking write failed:', err))
}
} catch (err) {
console.error('Click redirect error:', err)
// destinationUrl already set to fallback above
}
return Response.redirect(destinationUrl, 302)
}
Handle the missing-link-ID case explicitly — either redirect to a documented fallback URL or return a 404 with a helpful message, never a bare 500.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Campaign Analytics & Attribution Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · reliability — Reliability — fault tolerance
Taxons
History
- 2026-04-18·v1.0.0·Initial import from campaign-analytics-attribution·automated