Repository: auth0/auth0-spa-js (ts)

Issue:
Throw Explicit errors on failure when bootstrapping
At the moment if wrong arguments are passed or for some reason, the authorization server fails to respond catastrophically the library will timeout and return an object.

https://github.com/auth0/auth0-spa-js/blob/master/src/index.ts#L43

It'd be better to throw an error when initializing with `createAuth0Client` and let the apple handle what it must do when AS is unavailable. This might also be helpful when initially setting up (eg: Point to docs in dev bundle?)

Pull request description:
[SDK-1125] createAuth0Client now throws errors that are not login_required
### Description

Errors on start up thrown by `getTokenSilently` should be exposed if they are anything other than `login_required`. This may help diagnose configuration issues that might be difficult to debug if the developer has to wait 60 seconds to see them (thanks to the auth timeout when using an iframe and `response_mode: web_message`.

### References

Fixes #208 

### Testing

- [X] This change adds test coverage for new/changed/fixed functionality

### Checklist

- [X] I have added documentation for new/changed functionality in this PR or in auth0.com/docs
- [X] All active GitHub checks for tests, formatting, and security are passing
- [X] The correct base branch is being used, if not `master`


Patch:
diff --git a/src/index.ts b/src/index.ts
index fe9b9c4..0e6242d 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -28,7 +28,9 @@ export default async function createAuth0Client(options: Auth0ClientOptions) {
       ignoreCache: true
     });
   } catch (error) {
-    // ignore
+    if (error.error !== 'login_required') {
+      throw error;
+    }
   }
   return auth0;
 }


Test patch:
diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts
index 9063ec9..64ec321 100644
--- a/__tests__/index.test.ts
+++ b/__tests__/index.test.ts
@@ -111,13 +111,64 @@ describe('Auth0', () => {
         domain: TEST_DOMAIN,
         client_id: TEST_CLIENT_ID
       });
+
       expect(auth0).toBeInstanceOf(Auth0Client);
     });
+
     it('should call `utils.validateCrypto`', async () => {
       const { utils } = await setup();
+
       expect(utils.validateCrypto).toHaveBeenCalled();
     });
+
+    it('should absorb "login_required" errors', async () => {
+      const { utils, storage } = await setup();
+
+      utils.runIframe.mockImplementation(() => {
+        throw {
+          error: 'login_required',
+          error_message: 'Login required'
+        };
+      });
+
+      storage.get.mockReturnValue(true);
+
+      const auth0 = await createAuth0Client({
+        domain: TEST_DOMAIN,
+        client_id: TEST_CLIENT_ID
+      });
+
+      expect(auth0).toBeInstanceOf(Auth0Client);
+      expect(utils.runIframe).toHaveBeenCalled();
+    });
+
+    it('should throw other errors that are not "login_required"', async () => {
+      const { utils, storage } = await setup();
+
+      utils.runIframe.mockImplementation(() => {
+        throw {
+          error: 'some_other_error',
+          error_message: 'This is a different error to login_required'
+        };
+      });
+
+      storage.get.mockReturnValue(true);
+
+      // We expect one assertion, meaning that if the function under test
+      // does not throw, it will still fail the test.
+      expect.assertions(1);
+
+      try {
+        await createAuth0Client({
+          domain: TEST_DOMAIN,
+          client_id: TEST_CLIENT_ID
+        });
+      } catch (e) {
+        expect(e.error).toEqual('some_other_error');
+      }
+    });
   });
+
   describe('loginWithPopup()', () => {
     it('opens popup', async () => {
       const { auth0, utils } = await setup();