Skip to content
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

Support v2 account API error shapes #554

Closed
wants to merge 3 commits into from
Closed

Conversation

ecooper
Copy link
Contributor

@ecooper ecooper commented Jan 6, 2025

Problem

In the future, v2 endpoints of the account API will have a different API shape than the current v1 shape.

v1:

{
  code: string,
  reason: string,
}

v2:

{
  error: {
    code: string,
    message: string,
    metadata: Record<string, any>
  }
}

(excuse the TS types, 🤣 )

Both API endpoints versions will need to be supported.

Solution

The existing parseResponse function already handles translating Account API errors to a catchable error in the CLI. By adding a new helper, parseErrorResponse, we can normalize the error shape before building the error.

Result

v1 and v2 error shapes are supported transparently for the consuming code.

Testing

Updated parseResponse tests to demonstrate normalizing and a few other small changes.

@ecooper ecooper requested a review from a team as a code owner January 6, 2025 23:04
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.

1 participant