Skip to content

✨ feat: add treaty error shorthand option #183

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

m1212e
Copy link

@m1212e m1212e commented Feb 24, 2025

This option allows for simple usage of the treaty client. It offers a shouldThrow in the config which makes the client throw in case of an error instead of returning the whole response object.

This reduces the boilerplate in environments where throwing is desired and simplifies the response handling:

const userResult = await backend.auth["upsert-self"].post();
if (userResult.error) {
  throw userResult.error;
}
const user = userResult.data;

// becomes
const user = await backend.auth["upsert-self"].post();

This way the users can decide how the client should behave per default.
Let me hear what you think!

@kravetsone
Copy link

maybe just throw?

@m1212e
Copy link
Author

m1212e commented Feb 24, 2025

You mean the field name of the config option?

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.

2 participants