Skip to content

fix: Export ConflictException and add code#1563

Open
davidcornu wants to merge 2 commits intoworkos:mainfrom
davidcornu:export-conflict-exception
Open

fix: Export ConflictException and add code#1563
davidcornu wants to merge 2 commits intoworkos:mainfrom
davidcornu:export-conflict-exception

Conversation

@davidcornu
Copy link
Copy Markdown
Contributor

@davidcornu davidcornu commented Apr 20, 2026

Description

Some operations like workos.authorization.deleteOrganizationRole will throw a ConflictException that needs to be handled appropriately (e.g. to customize the error message before showing it to users).

However, ConflictException isn't current exported so it can't be used to perform type-safe error handling (e.g. error instanceof ConflictException). It also doesn't pass along the code property which is needed to differentiate error types (e.g. https://workos.com/docs/reference/roles/custom-role#delete-a-custom-role).

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

Summary by CodeRabbit

  • Chores
    • Updated internal exception exports for better code organization.

@davidcornu davidcornu requested review from a team as code owners April 20, 2026 18:51
@davidcornu davidcornu requested a review from rwtombaugh April 20, 2026 18:51
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

Exported the conflict exception from the exceptions barrel; updated ConflictException to include an optional code property; and adjusted HTTP error handling to pass the code from 409 responses into ConflictException.

Changes

Cohort / File(s) Summary
Exception Barrel Export
src/common/exceptions/index.ts
Added export * from './conflict.exception'; to re-export the conflict exception via the exceptions barrel.
Conflict Exception
src/common/exceptions/conflict.exception.ts
Added readonly code?: string to ConflictException and updated the constructor signature to accept an optional code?: string, assigning it to this.code.
HTTP Error Handling
src/workos.ts
Updated 409 (Conflict) error branch in handleHttpError to include code from the error response when constructing ConflictException (now passes { requestID, message, error, code }).
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: exporting ConflictException and adding the code property.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly explains the problem and solution, covering all essential points including the need for ConflictException export and code property exposure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@davidcornu davidcornu changed the title Export ConflictException fix: Export ConflictException Apr 20, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 20, 2026

Greptile Summary

This PR exports ConflictException from the package's public surface so consumers can use instanceof ConflictException for type-safe error handling. It also adds a code field to ConflictException (matching the pattern of other exceptions like NotFoundException) and threads code through from the HTTP 409 response in workos.ts.

Confidence Score: 5/5

Safe to merge — small, well-scoped fix with no regressions.

All three changes are minimal and consistent with the existing exception pattern in the codebase. No logic is altered; ConflictException is simply exported and enriched with the already-available code field.

No files require special attention.

Important Files Changed

Filename Overview
src/common/exceptions/conflict.exception.ts Adds optional code property and constructor parameter to ConflictException, consistent with how other exceptions (e.g. NotFoundException) expose code.
src/common/exceptions/index.ts Adds export * from './conflict.exception' so ConflictException is part of the public package exports via src/index.ts.
src/workos.ts Passes code from the 409 response body when constructing ConflictException, so callers can inspect the machine-readable error code.

Sequence Diagram

sequenceDiagram
    participant User as Consumer Code
    participant SDK as WorkOS SDK (workos.ts)
    participant API as WorkOS API

    User->>SDK: workos.authorization.deleteOrganizationRole(...)
    SDK->>API: HTTP DELETE request
    API-->>SDK: 409 Conflict { message, error, code }
    SDK-->>User: throw ConflictException({ requestID, message, error, code })
    User->>User: catch (e) { if (e instanceof ConflictException) ... }
Loading

Reviews (2): Last reviewed commit: "Expose `code` on `ConflictException`" | Re-trigger Greptile

@davidcornu davidcornu changed the title fix: Export ConflictException fix: Export ConflictException and add code Apr 20, 2026
@@ -25,5 +28,7 @@ export class ConflictException extends Error implements RequestException {
} else {
this.message = `An conflict has occurred on the server.`;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixing this typo would probably be a breaking change 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant