Always return code
or error
in responses as ErrorCode
when present
#203
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We currently set
ErrorCode
inHTTPError
from thecode
field in raw responses from the WorkOS API, but only in certain cases, like getting a422
.Otherwise,
ErrorCode
ends up as empty string in other cases. For example, as noted in #198, when an invalid Authorization Code is provided to the token endpoint, the following raw error is returned:However, the
ErrorCode
is not populated, making it hard to handle this (or other) particular errors.This PR updates the error parsing logic to always attempt to populate
ErrorCode
withcode
from the response, falling back toerror
when not present. In all cases I'm aware of,error
should be a discrete error type identifier suitable for dispatching on in response handling code.Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.