Skip to content

Conversation

@atainter
Copy link
Contributor

Description

Some customers have reported receiving non-json responses from the workos API. These raise a syntax error when the Node.js ADK attempts to parse the json. This PR adds rawBody and requestID to a new ParseError exception for debugging purposes.

@atainter atainter requested a review from a team as a code owner July 18, 2025 18:34
@atainter atainter requested a review from mattgd July 18, 2025 18:34
Copy link
Contributor

@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 enhances error handling in the WorkOS Node.js SDK by introducing a new ParseError class to handle cases where non-JSON responses are received from the WorkOS API. The changes add important debugging information (raw response body and request ID) when JSON parsing fails.

The implementation involves:

  1. Adding a new ParseError class that extends Error and implements RequestException
  2. Modifying the HTTP methods (post, get, put) to capture and include debugging information when parsing fails
  3. Adding a new handleParseError method to extract the raw response and request ID

This change will significantly improve debugging capabilities when investigating API response issues, particularly beneficial for support scenarios.

Confidence score: 5/5

  1. This PR is very safe to merge as it only adds error handling improvements
  2. The changes are well-contained, only affecting error handling paths, and can't impact successful API calls
  3. No files need special attention as the changes are straightforward and well-implemented

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

Comment on lines +4 to +5
readonly name = 'ParseError';
readonly status = 500;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Ensure 500 is the correct status code for parse errors. Consider if 400 might be more appropriate since it's a client-side parsing issue.

atainter and others added 3 commits July 18, 2025 11:36
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@mattgd mattgd left a comment

Choose a reason for hiding this comment

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

Thanks for adding this. Could we add a test to exercise the ParseError behavior?

Copy link
Contributor

@mattgd mattgd left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this!

@atainter atainter merged commit 9fa2de0 into main Jul 18, 2025
5 checks passed
@atainter atainter deleted the at-add-raw-body-syntax-error-for-debugging branch July 18, 2025 21:31
atainter added a commit that referenced this pull request Jul 25, 2025
## Description
Missed a codepath in #1313 where non-200 responses would attempt to
parse the body
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.

3 participants