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

feat: support throwing errors instead of returning them #1022

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

kiwicopple
Copy link
Member

@kiwicopple kiwicopple commented Jan 14, 2025

Fixes #1020

Add support for throwOnError option in AuthClient to throw errors instead of returning them.

  • GoTrueClient Changes:

    • Add throwOnError option to GoTrueClient constructor.
    • Modify methods to throw errors when throwOnError is true.
    • Update methods like signUp, signInWithPassword, updateUser, and others to throw errors if throwOnError is true.
  • AuthClient Changes:

    • Update AuthClient to pass throwOnError option to GoTrueClient.
  • Tests:

    • Add tests in test/GoTrueClient.test.ts to verify throwOnError functionality.

For more details, open the Copilot Workspace session.

Fixes #1020

Add support for `throwOnError` option in `AuthClient` to throw errors instead of returning them.

* **GoTrueClient Changes:**
  - Add `throwOnError` option to `GoTrueClient` constructor.
  - Modify methods to throw errors when `throwOnError` is true.
  - Update methods like `signUp`, `signInWithPassword`, `updateUser`, and others to throw errors if `throwOnError` is true.

* **AuthClient Changes:**
  - Update `AuthClient` to pass `throwOnError` option to `GoTrueClient`.

* **Tests:**
  - Add tests in `test/GoTrueClient.test.ts` to verify `throwOnError` functionality.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/supabase/auth-js/issues/1020?shareId=XXXX-XXXX-XXXX-XXXX).
* Correct syntax for `expect` assertions to use `.not.toBeNull()` and `.not.toEqual()` instead of `not toBeNull` and `not toEqual`
src/AuthClient.ts Outdated Show resolved Hide resolved
Copy link
Member Author

@kiwicopple kiwicopple left a comment

Choose a reason for hiding this comment

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


@kiwicopple kiwicopple changed the title Support throwing errors instead of returning them feat: support throwing errors instead of returning them Jan 16, 2025
Copy link
Contributor

@hf hf left a comment

Choose a reason for hiding this comment

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

Maybe a better way to deal with this is to have a function like so:

private function _returnResult<D, E>(result: { data: D, error: E }): { data: D, error: E } {
  if (this.throwOnError && result.error) {
    throw result.error
  }

  return result
}

Then each time we return the object we call:

return this._returnResult({ data: null, error })

It will be easier to spot and we could also potentially write a lint rule for it so it's not forgotten.

@hf
Copy link
Contributor

hf commented Jan 17, 2025

Don't worry about the check-conventional-commits errors, I'll fix those before merging.

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.

Support throwing errors instead of returning them
3 participants