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

Adding guard #277

Merged
merged 7 commits into from
Mar 28, 2023
Merged

Adding guard #277

merged 7 commits into from
Mar 28, 2023

Conversation

manas-vessel
Copy link
Contributor

Description

Please provide a detailed description of the changes and the intent behind them :)

This lets you set a default value if an async function errors out.

const users = await guard(fetchUsers()) ?? [];

You can choose to guard only specific errors too

const isInvalidUserError = (err: any) => err.code === 'INVALID_ID'
const user = await guard(fetchUser, isInvalidUserError)(id) ?? DEFAULT_USER;

Checklist

  • Changes are covered by tests if behavior has been changed or added
  • Tests have 100% coverage
  • If code changes were made, the version in package.json has been bumped (matching semver)
  • If code changes were made, the yarn build command has been run and to update the cdn directory
  • If code changes were made, the documentation (in the /docs directory) has been updated

Resolves

If the PR resolves an open issue tag it here. For example, Resolves #34

@vercel
Copy link

vercel bot commented Mar 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
radash-docs ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 28, 2023 at 6:57PM (UTC)

@sodiray sodiray merged commit 77cb220 into sodiray:master Mar 28, 2023
aleclarson referenced this pull request in radashi-org/radashi Jun 24, 2024
* Adding guard

* Adding tests

* better guard

* running build

* running prettier

* add docs

* version bump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants