Skip to content

Fix SSO error handling to surface detailed validation errors #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nicknisi
Copy link
Contributor

@nicknisi nicknisi commented Jul 17, 2025

Summary

Fixes the SSO module's error handling to surface detailed validation errors instead of swallowing them with generic "Something went wrong" messages.

Problem: The SSO profile_and_token method used custom error handling that bypassed the standard SDK error processing, converting detailed 422 validation errors into generic messages. This created poor developer experience when debugging OAuth code exchange failures.

Solution: Remove the custom error handling and use the standard execute_request method like all other SDK modules, which properly surfaces field-specific validation errors.

Changes

  • Remove check_and_raise_profile_and_token_error method that was swallowing detailed errors
  • Update profile_and_token to use execute_request instead of client.request
  • Leverage existing 422 error handling infrastructure that properly processes field-specific errors
  • Add comprehensive error handling tests to verify proper error object attributes
  • Ensure SSO error handling is consistent with other SDK modules

Impact

Before

# 422 error with detailed validation info becomes:
raise APIError.new(message: "Something went wrong", http_status: nil, ...)

After

# 422 error properly surfaces field details:
raise UnprocessableEntityError.new(
  message: "Validation failed (code: missing_required_parameter)",
  http_status: 422,
  code: "invalid_request_parameters", 
  errors: "code: missing_required_parameter",
  ...
)

Breaking Changes

None - this is a bug fix that improves error handling without changing the public API.

Semver: PATCH (bug fix, backward compatible)

Previously, the SSO module's profile_and_token method used custom error
handling that swallowed detailed 422 validation errors and converted them
to generic "Something went wrong" messages. This created poor developer
experience when debugging OAuth code exchange failures.

Changes:
- Remove check_and_raise_profile_and_token_error method that bypassed standard error handling
- Update profile_and_token to use execute_request instead of client.request
- Leverage existing 422 error handling infrastructure that properly surfaces field-specific errors
- Add comprehensive error handling tests to verify proper error object attributes
- Ensure SSO error handling is consistent with other SDK modules

The fix allows developers to see specific validation errors (e.g., "code: missing_required_parameter")
instead of generic error messages, significantly improving debugging experience.
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR fixes a critical error handling issue in the SSO module of the WorkOS Ruby SDK. Previously, the profile_and_token method was using custom error handling that converted detailed validation errors (HTTP 422) into generic "Something went wrong" messages, which made debugging OAuth code exchange failures unnecessarily difficult.

The changes:

  1. Remove the check_and_raise_profile_and_token_error method that was masking detailed errors
  2. Switch from direct client.request to using execute_request, leveraging the SDK's standard error processing
  3. Allow proper surfacing of field-specific validation errors through the standard error handling infrastructure

The change makes error handling more consistent across the SDK and significantly improves the developer experience by providing actionable error messages instead of generic ones.

Confidence score: 5/5

  1. This PR is very safe to merge as it's a clear improvement in error handling with comprehensive test coverage
  2. The changes are well-tested with both existing and new test cases, improve developer experience, and don't introduce breaking changes
  3. Key files to review:
    • lib/workos/sso.rb
    • spec/lib/workos/sso_spec.rb

2 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@nicknisi nicknisi requested a review from cmatheson July 17, 2025 20:09
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