Skip to content

Normalize Salesforce connection errors to appropriate HTTP status codes#1846

Merged
paustint merged 1 commit into
mainfrom
fix/improve-org-connection-expiration-handling
Jul 2, 2026
Merged

Normalize Salesforce connection errors to appropriate HTTP status codes#1846
paustint merged 1 commit into
mainfrom
fix/improve-org-connection-expiration-handling

Conversation

@paustint

@paustint paustint commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Improve error handling for Salesforce connection issues by normalizing specific errors to their corresponding HTTP status codes. This change prevents misleading 500 errors from being sent to clients for authentication failures and ensures that users are prompted to reconnect when necessary.

Copilot AI review requested due to automatic review settings July 1, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves API error handling for known Salesforce connection/auth failures by mapping them to deterministic 4xx HTTP status codes (instead of sometimes passing through Salesforce’s upstream 5xx statuses), reducing misleading “server error” responses and avoiding false 5xx alerting.

Changes:

  • Detects known Salesforce connection/auth error messages and normalizes the HTTP status to 401 (auth/connection) or 403 (“REST API not enabled”).
  • Reuses the same detection for (a) org invalidation side-effects and (b) deferred-mode error body enrichment, avoiding duplicated condition checks.
  • Adds Vitest coverage to ensure both UserFacingError and generic/unwrapped errors normalize to 4xx as intended.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/api/src/app/utils/response.handlers.ts Adds message-based detection for known Salesforce connection errors and normalizes response status to 401/403 across both typed and generic error paths.
apps/api/src/app/utils/tests/response.handlers.spec.ts Adds tests validating normalization behavior and that org invalidation side-effects still occur for expired-token scenarios.

@paustint paustint merged commit a6ebecd into main Jul 2, 2026
9 checks passed
@paustint paustint deleted the fix/improve-org-connection-expiration-handling branch July 2, 2026 14:41
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