This repository was archived by the owner on Oct 10, 2025. It is now read-only.
  
  
  - 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 194
feat: support throwing errors instead of returning them #1022
          
     Closed
      
      
    Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    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`
              
                    j4w8n
  
              
              reviewed
              
                  
                    Jan 15, 2025 
                  
              
              
            
            
              
                    kiwicopple
  
              
              commented
              
                  
                    Jan 16, 2025 
                  
              
              
            
            
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.
              
                    hf
  
              
              reviewed
              
                  
                    Jan 17, 2025 
                  
              
              
            
            
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. | 
| moved: supabase/supabase-js#1766 | 
  
      Sign up for free
      to subscribe to this conversation on GitHub.
      Already have an account?
      Sign in.
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Fixes supabase/supabase-js#1688
Add support for
throwOnErroroption inAuthClientto throw errors instead of returning them.GoTrueClient Changes:
throwOnErroroption toGoTrueClientconstructor.throwOnErroris true.signUp,signInWithPassword,updateUser, and others to throw errors ifthrowOnErroris true.AuthClient Changes:
AuthClientto passthrowOnErroroption toGoTrueClient.Tests:
test/GoTrueClient.test.tsto verifythrowOnErrorfunctionality.For more details, open the Copilot Workspace session.