-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
base: master
Are you sure you want to change the base?
Conversation
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`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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.
Don't worry about the check-conventional-commits errors, I'll fix those before merging. |
Fixes #1020
Add support for
throwOnError
option inAuthClient
to throw errors instead of returning them.GoTrueClient Changes:
throwOnError
option toGoTrueClient
constructor.throwOnError
is true.signUp
,signInWithPassword
,updateUser
, and others to throw errors ifthrowOnError
is true.AuthClient Changes:
AuthClient
to passthrowOnError
option toGoTrueClient
.Tests:
test/GoTrueClient.test.ts
to verifythrowOnError
functionality.For more details, open the Copilot Workspace session.