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

fix: handle single error responses #49

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

connorlindsey
Copy link
Contributor

Description

The API typically returns an array of error messages but in some cases, returns a single error. This update checks if errors is an array or single instance. If it's a single error, it wraps it in an array so that formatting the error message works correctly in UnprocessableEntityException

Resolves #47

const { errors } = data;
const errors = Array.isArray(data.errors)
? data.errors
: [data.errors];
Copy link
Contributor

Choose a reason for hiding this comment

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

If errors is null or undefined, then won't this end up as [null]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, added an extra check if errors is not defined

Copy link
Contributor

@cjbell cjbell left a comment

Choose a reason for hiding this comment

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

💯

@connorlindsey connorlindsey merged commit 2d1609d into main Jan 24, 2024
@connorlindsey connorlindsey deleted the connor-kno-5071-node-sdk-errors-not-iterable branch January 24, 2024 18:44
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.

v0.6.0 not working
2 participants