Make upload analytics non-fatal in /api/upload and add tagged structured error logs - #541
Merged
Merged
Conversation
Co-authored-by: abhitrueprogrammer <67090539+abhitrueprogrammer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update upload API route to handle PostHog errors gracefully
Make upload analytics non-fatal in Oct 5, 2026
/api/upload and add tagged structured error logs
Collaborator
|
@copilot shouldn't the posthog init be in a seperate function (or not?) and should this be changed in both the routes that use server actions (src/app/api/request/route.ts) |
Co-authored-by: abhitrueprogrammer <67090539+abhitrueprogrammer@users.noreply.github.com>
Contributor
Author
|
Collaborator
|
lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Purpose
Prevent PostHog failures from converting successful uploads into
500responses insrc/app/api/upload/route.ts, while preserving existing upload behavior and response shape.🖼️ Showcase
Terminal/API behavior intent:
201response even if analytics fails.[UPLOAD_ANALYTICS_ERROR].[UPLOAD_ROUTE_ERROR]and still return generic upload500.🔧 Changes
Separated failure domains
try/catchafteruploadPaper(...)succeeds.Structured tagged logging
[UPLOAD_ANALYTICS_ERROR]log payload withname,message,stack.[UPLOAD_ROUTE_ERROR]structured log in the outer catch with the same Error/non-Error normalization.No behavioral drift in upload contract
➕ Additional Notes
src/app/api/upload/route.tschanged.