Skip to content

OUT-3674 | Error: Something went wrong in getCustomFieldAccess#58

Merged
arpandhakal merged 1 commit into
mainfrom
OUT-3674
May 15, 2026
Merged

OUT-3674 | Error: Something went wrong in getCustomFieldAccess#58
arpandhakal merged 1 commit into
mainfrom
OUT-3674

Conversation

@arpandhakal
Copy link
Copy Markdown
Collaborator

@arpandhakal arpandhakal commented May 13, 2026

Summary

  • Wrap /api/custom-field-access GET in try/catch + handleError so Copilot SDK / Prisma errors surface their real status and message instead of an opaque Next.js 500 (matches the existing pattern in profile-update-history/route.ts).
  • In getCustomFieldAccess on both app/page.tsx and app/manage/page.tsx, include the response status and a 200-char body snippet in the thrown error.

This is a diagnostic-only change. Sentry issue PROFILE-MANAGER-35 (24 events) currently throws a generic Something went wrong in getCustomFieldAccess with no upstream context — we don't know whether the API route is failing on SDK auth, the Copilot platform API, Prisma, or schema validation. After this lands, the next batch of events will show the real cause (e.g. getCustomFieldAccess failed: 401 {"message":"Unable to authorize Copilot SDK."}), letting us decide whether PM-35 is the same non-actionable token-rejection population as PROFILE-MANAGER-34 or something we can actually fix.

Resolves OUT-3674 once we have enough new events to triage.

Test plan

  • Hit / and /manage with a valid token — both pages render normally (happy path unchanged).
  • Hit /api/custom-field-access with a malformed token — confirm route returns a JSON error body (not an unhandled 500).
  • After deploy, watch PROFILE-MANAGER-35 in Sentry for ~a week and confirm new event titles include status codes / upstream messages.

🤖 Generated with Claude Code

The API route now propagates SDK/DB errors via handleError instead of
bubbling an opaque 500, and the page-level helper includes the status
code and response body snippet in its thrown error. Improves Sentry
diagnostics for PROFILE-MANAGER-35 so we can distinguish bad-token
failures from other upstream causes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 13, 2026

OUT-3674

@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
client-profile-manager Ready Ready Preview, Comment May 13, 2026 9:45am

Request Review

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 13, 2026

Greptile Summary

This is a targeted diagnostic change to improve error observability for a recurring Sentry issue (PROFILE-MANAGER-35). Previously, failures in getCustomFieldAccess surfaced as an opaque 500 with no upstream context; now the route wraps its logic in a try/catch with handleError, and the page-level callers include the HTTP status code and a 200-char body snippet in the thrown error.

  • route.ts: Wraps the Copilot SDK call, Prisma lookup, and response assembly in a try/catch, delegating to the existing handleError utility — matching the pattern already in use elsewhere in the codebase.
  • page.tsx / manage/page.tsx: Both getCustomFieldAccess helpers now read the response body on failure and embed status + a truncated body into the thrown Error, giving Sentry enough context to triage the real root cause.

Confidence Score: 5/5

Safe to merge — the change only adds error handling that was already missing; the happy path is entirely unchanged.

The route change wraps existing logic in a try/catch and hands off to handleError, which is already used by other routes. The page-level error messages include the response status and a truncated body from the internal API's own JSON error response, which does not contain credentials. No logic paths were altered, only error surfacing improved.

No files require special attention. All three files make narrow, consistent changes.

Important Files Changed

Filename Overview
src/app/api/custom-field-access/route.ts Adds try/catch + handleError to the GET handler; consistent with the codebase pattern. PUT handler remains unwrapped, but that is pre-existing.
src/app/page.tsx Error message now includes HTTP status and a truncated response body for Sentry diagnostics; response body is internal JSON and does not contain credentials.
src/app/manage/page.tsx Mirrors the identical change made in page.tsx; both files updated consistently.

Sequence Diagram

sequenceDiagram
    participant Browser
    participant PageServer as Next.js Server (page / manage/page)
    participant Route as /api/custom-field-access
    participant Copilot as Copilot SDK
    participant DB as Prisma

    Browser->>PageServer: GET page request
    PageServer->>Route: fetch /api/custom-field-access
    Route->>Copilot: getCustomFields()
    alt Error (e.g. auth failure)
        Copilot-->>Route: throws CopilotApiError
        Route->>Route: "catch(error) -> handleError(error)"
        Route-->>PageServer: JSON error response with status code
        PageServer->>PageServer: "res.ok == false"
        PageServer->>PageServer: read body.slice(0,200)
        PageServer-->>PageServer: throw Error with status + body snippet
        Note over PageServer: Sentry captures full error context
    else Success
        Copilot-->>Route: customFields array
        Route->>DB: findAll(portalId)
        DB-->>Route: customFieldAccesses
        Route-->>PageServer: JSON data response
        PageServer-->>Browser: Rendered page
    end
Loading

Reviews (1): Last reviewed commit: "fix(OUT-3674): surface real cause of get..." | Re-trigger Greptile

@arpandhakal arpandhakal merged commit ce9b74c into main May 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants