Skip to content
Closed
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
20 changes: 13 additions & 7 deletions app/(frontend)/stats/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ export async function POST(
const headers = new Headers(req.headers)
headers.delete('host')

const upstream = await fetch(destination, {
method: 'POST',
headers,
body: req.body,
// @ts-ignore -- duplex is required for streaming request bodies in Node fetch
duplex: 'half',
})
let upstream: Response
try {
upstream = await fetch(destination, {
method: 'POST',
headers,
body: req.body,
// @ts-ignore -- duplex is required for streaming request bodies in Node fetch
duplex: 'half',
})
} catch {
// Umami unreachable (e.g. in E2E/test environments) — fail silently.
return new NextResponse(null, { status: 204 })
}

return new NextResponse(upstream.body, {
status: upstream.status,
Expand Down
9 changes: 3 additions & 6 deletions src/widgets/UmamiWidget/UmamiWidget.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const login = async (): Promise<string | null> => {

const data = await response.json()
token = (data.token as string) ?? null
} catch (error) {
console.error('Error logging in to Umami:', error)
} catch {
token = null
}
return token
Expand All @@ -40,8 +39,7 @@ const verify = async (): Promise<boolean> => {
})

return response.ok
} catch (error) {
console.error('Error verifying token:', error)
} catch {
return false
}
}
Expand Down Expand Up @@ -97,8 +95,7 @@ const fetcher = async <T extends object>(url: URL | string): Promise<T | null> =

await set(url.toString(), json as T, CACHE_TTL_SECONDS)
return json
} catch (error) {
console.error('Error fetching Umami data:', error)
} catch {
return null
}
}
Expand Down
Loading