Repository navigation
feat: export NetworkError from auth0-spa-js #1142
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -443,6 +443,33 @@ ngOnInit() { | |
| } | ||
| ``` | ||
|
|
||
| If a token request from `getAccessTokenSilently` or `AuthHttpInterceptor` fails (for example, the device is offline or a browser extension blocks it), the SDK emits a `NetworkError` after retrying. If the request times out, it emits a `TimeoutError` instead. Without refresh tokens, the SDK first loads an iframe, which can't detect network failures, so being offline usually gives a `TimeoutError`. | ||
|
|
||
| These errors don't mean the user's session is invalid, so show an offline message or retry later instead of asking the user to log in again. `PopupTimeoutError` is also a `TimeoutError`, but it means the user didn't finish a popup login in time, so the example leaves it out: | ||
|
|
||
| ```ts | ||
| import { filter } from 'rxjs/operators'; | ||
| import { | ||
| NetworkError, | ||
| PopupTimeoutError, | ||
| TimeoutError, | ||
| } from '@auth0/auth0-angular'; | ||
|
|
||
| ngOnInit() { | ||
| this.authService.error$.pipe( | ||
| filter( | ||
| (e) => | ||
| (e instanceof NetworkError || e instanceof TimeoutError) && | ||
| !(e instanceof PopupTimeoutError) | ||
| ) | ||
| ).subscribe(() => { | ||
| // temporary network issue: show an offline message or retry later | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| If the login callback fails this way, `error$` also emits a `NetworkError` or `TimeoutError`, and the SDK navigates to `errorPath` (or `/` if it isn't set). The login can't be retried, so call `loginWithRedirect` once the network is back. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Distinguish manual callback handling. With
|
||
|
|
||
| ## Organizations | ||
|
|
||
| [Organizations](https://auth0.com/docs/organizations) is a set of features that provide better support for developers who build and maintain SaaS and Business-to-Business (B2B) applications. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
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.
This
error$subscription also gets login-callback failures: the constructor'shandleRedirectCallback()does a token exchange, so offline it emits aNetworkErrororTimeoutErrorand navigates toerrorPath. That callback can't be retried, because spa-js removes the transaction before the exchange (Auth0Client.ts#L809). The spa-js and auth0-react docs call this out, so suggest the same here: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.
Thanks, added in b665d91.