Skip to content

docs: update Link endpoint — 404 for user-not-found, 409 for already-linked#248

Merged
veverkap merged 2 commits into
mainfrom
docs/fix-link-404-status-code-c6cc44487a210de5
May 11, 2026
Merged

docs: update Link endpoint — 404 for user-not-found, 409 for already-linked#248
veverkap merged 2 commits into
mainfrom
docs/fix-link-404-status-code-c6cc44487a210de5

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 10, 2026

Summary

PR #231 fixed the OIDC and OAuth2 Link endpoint to return 404 Not Found when Users.FindByID returns ErrNotFound, instead of conflating it with 409 Conflict (reserved for the "account already linked" case).

This PR updates the HTTP status code reference tables in the handler documentation to accurately reflect that distinction.

Changes

  • docs/handler/oidc.md — split the Link | 409 Conflict row into:
    • Link | 404 Not Found — user not found (ErrNotFound from Users.FindByID)
    • Link | 409 Conflict — account already linked to an OIDC identity
  • docs/handler/oauth2.md — same split for OAuth2Handler

Motivation

Before this fix, clients following the API reference would incorrectly expect 409 when a user account had been deleted between nonce issuance and link initiation. The 404 response is semantically correct and more actionable for API consumers.

Testing

Documentation-only change; no functional code modified.

Generated by Update Docs · ● 799.5K ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/update-docs.md@96b9d4c39aa22359c0b38265927eadb31dcf4e2a

Greptile Summary

This PR updates the HTTP status code reference tables in docs/handler/oidc.md and docs/handler/oauth2.md to reflect the fix from PR #231, which made the Link endpoint return 404 Not Found when Users.FindByID returns ErrNotFound instead of conflating it with 409 Conflict.

  • oidc.md — splits the old combined Link | 409 row into a 404 row (user not found) and a 409 row (account already linked); the existing 500 description already covers the DB-error case.
  • oauth2.md — same split; however, the 500 description for Link omits the "DB error when looking up user by ID" case that exists in the handler code and is documented in oidc.md.

Confidence Score: 5/5

Documentation-only change; no functional code modified, safe to merge.

Both doc files correctly split the old combined row into the accurate 404 and 409 responses, matching the handler implementations. The one gap — the missing DB-error note in oauth2.md's 500 row — is a minor doc omission with no impact on the running service.

docs/handler/oauth2.md — the Link 500 description is slightly less complete than its oidc.md counterpart.

Important Files Changed

Filename Overview
docs/handler/oauth2.md Correctly splits the old combined 409 row into 404 (user not found) and 409 (already linked); the 500 description for Link omits the DB-error-on-FindByID case that is present in oidc.md and in the handler code.
docs/handler/oidc.md Correctly splits the old combined 409 row into 404 (user not found) and 409 (already linked); 500 description already mentions the DB-error case.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Link handler called] --> B{LinkNonces nil?}
    B -- Yes --> C[503 Service Unavailable]
    B -- No --> D{Nonce in query?}
    D -- No --> E[400 Bad Request]
    D -- Yes --> F[consumeLinkNonce]
    F --> G{Error?}
    G -- ErrNotFound --> H[401 Unauthorized]
    G -- Other error --> I[500 Internal Server Error]
    G -- nil --> J[Users.FindByID]
    J --> K{Error?}
    K -- ErrNotFound --> L[404 Not Found]
    K -- Other error --> M[500 Internal Server Error]
    K -- nil --> N{OIDCSubject != nil?}
    N -- Yes --> O[409 Conflict]
    N -- No --> P[302 Found — redirect to provider]
Loading

Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
docs/handler/oauth2.md:180
The `Link | 500` description omits the case where `Users.FindByID` returns a non-`ErrNotFound` error. The OAuth2 handler code writes `http.StatusInternalServerError` for that path (same as the OIDC handler), and `oidc.md` explicitly documents it as "DB error when looking up user by ID". Without this note, API consumers won't know that a transient database error during link initiation can also produce a 500.

```suggestion
| `Link` | 500 Internal Server Error | Nonce store error, DB error when looking up user by ID, or failed to initiate redirect |
```

Reviews (2): Last reviewed commit: "docs: use "external identity" for 409 Li..." | Re-trigger Greptile

… for already-linked

The OIDC/OAuth2 Link endpoint previously returned 409 Conflict for both
"account already linked" and "user not found" conditions. PR #231 fixed
the handler to return 404 Not Found when Users.FindByID returns ErrNotFound,
reserving 409 Conflict solely for the already-linked case.

Update HTTP status code tables in docs/handler/oidc.md and
docs/handler/oauth2.md to reflect this distinction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added automation documentation Improvements or additions to documentation labels May 10, 2026
@veverkap veverkap marked this pull request as ready for review May 11, 2026 15:48
@veverkap veverkap requested review from a team and Copilot May 11, 2026 15:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the handler documentation to reflect the corrected semantics of the OIDC/OAuth2 Link endpoints: returning 404 Not Found when the linking user no longer exists, while reserving 409 Conflict for the “already linked” case (aligning docs with PR #231 behavior).

Changes:

  • Update OIDCHandler docs to split the previous combined 409 case into distinct 404 (user missing) and 409 (already linked) entries.
  • Update OAuth2Handler docs similarly (with one wording inconsistency noted in a review comment).
Show a summary per file
File Description
docs/handler/oidc.md Splits Link status table entries to document 404 (user missing) vs 409 (already linked).
docs/handler/oauth2.md Splits Link status table entries to document 404 (user missing) vs 409 (already linked); 409 wording needs alignment with actual behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread docs/handler/oauth2.md Outdated
Comment thread docs/handler/oauth2.md Outdated
… and oidc docs

The OIDCSubject field is shared between OIDC and OAuth2 handlers, so a
409 fires regardless of which provider the user previously linked via.
Using "external identity" avoids implying provider specificity.
@veverkap veverkap merged commit 4d55984 into main May 11, 2026
13 checks passed
@veverkap veverkap deleted the docs/fix-link-404-status-code-c6cc44487a210de5 branch May 11, 2026 16:12
@github-actions github-actions Bot mentioned this pull request May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants