Differentiate connectivity and auth related errors
Summary: Cleaning up login session and connectivity handling. Reviewed By: passy Differential Revision: D28795342 fbshipit-source-id: ddc659d681f730c7183f364d8924e5c680f8a418
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fff489091e
commit
b7d7326bae
@@ -7,13 +7,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {
|
import React, {cloneElement, useState, useCallback, useMemo} from 'react';
|
||||||
cloneElement,
|
|
||||||
useState,
|
|
||||||
useCallback,
|
|
||||||
useMemo,
|
|
||||||
useEffect,
|
|
||||||
} from 'react';
|
|
||||||
import {Button, Divider, Badge, Tooltip, Avatar, Popover} from 'antd';
|
import {Button, Divider, Badge, Tooltip, Avatar, Popover} from 'antd';
|
||||||
import {
|
import {
|
||||||
MobileFilled,
|
MobileFilled,
|
||||||
@@ -50,7 +44,6 @@ import {showEmulatorLauncher} from './appinspect/LaunchEmulator';
|
|||||||
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
|
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
|
||||||
import {setStaticView, StaticView} from '../reducers/connections';
|
import {setStaticView, StaticView} from '../reducers/connections';
|
||||||
import {getInstance} from '../fb-stubs/Logger';
|
import {getInstance} from '../fb-stubs/Logger';
|
||||||
import {getUser} from '../fb-stubs/user';
|
|
||||||
import {SandyRatingButton} from '../chrome/RatingButton';
|
import {SandyRatingButton} from '../chrome/RatingButton';
|
||||||
import {filterNotifications} from './notification/notificationUtils';
|
import {filterNotifications} from './notification/notificationUtils';
|
||||||
import {useMemoize} from 'flipper-plugin';
|
import {useMemoize} from 'flipper-plugin';
|
||||||
@@ -58,7 +51,6 @@ import isProduction from '../utils/isProduction';
|
|||||||
import NetworkGraph from '../chrome/NetworkGraph';
|
import NetworkGraph from '../chrome/NetworkGraph';
|
||||||
import FpsGraph from '../chrome/FpsGraph';
|
import FpsGraph from '../chrome/FpsGraph';
|
||||||
import UpdateIndicator from '../chrome/UpdateIndicator';
|
import UpdateIndicator from '../chrome/UpdateIndicator';
|
||||||
import {UserNotSignedInError, UserUnauthorizedError} from '../utils/errors';
|
|
||||||
|
|
||||||
const LeftRailButtonElem = styled(Button)<{kind?: 'small'}>(({kind}) => ({
|
const LeftRailButtonElem = styled(Button)<{kind?: 'small'}>(({kind}) => ({
|
||||||
width: kind === 'small' ? 32 : 36,
|
width: kind === 'small' ? 32 : 36,
|
||||||
@@ -379,20 +371,6 @@ function LoginButton() {
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (config.showLogin) {
|
|
||||||
getUser().catch((error) => {
|
|
||||||
if (
|
|
||||||
error instanceof UserUnauthorizedError ||
|
|
||||||
error instanceof UserNotSignedInError
|
|
||||||
) {
|
|
||||||
showLogin();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return login ? (
|
return login ? (
|
||||||
<Popover
|
<Popover
|
||||||
content={
|
content={
|
||||||
|
|||||||
@@ -9,6 +9,20 @@
|
|||||||
|
|
||||||
import {InteractionReport} from 'flipper-plugin';
|
import {InteractionReport} from 'flipper-plugin';
|
||||||
|
|
||||||
|
export function isAuthError(
|
||||||
|
err: any,
|
||||||
|
): err is UserNotSignedInError | UserUnauthorizedError {
|
||||||
|
return (
|
||||||
|
err instanceof UserNotSignedInError || err instanceof UserUnauthorizedError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isConnectivityOrAuthError(
|
||||||
|
err: any,
|
||||||
|
): err is ConnectivityError | UserNotSignedInError | UserUnauthorizedError {
|
||||||
|
return err instanceof ConnectivityError || isAuthError(err);
|
||||||
|
}
|
||||||
|
|
||||||
export class CancelledPromiseError extends Error {
|
export class CancelledPromiseError extends Error {
|
||||||
constructor(msg: string) {
|
constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@@ -17,6 +31,14 @@ export class CancelledPromiseError extends Error {
|
|||||||
name: 'CancelledPromiseError';
|
name: 'CancelledPromiseError';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ConnectivityError extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = 'ConnectivityError';
|
||||||
|
}
|
||||||
|
name: 'ConnectivityError';
|
||||||
|
}
|
||||||
|
|
||||||
export class UserUnauthorizedError extends Error {
|
export class UserUnauthorizedError extends Error {
|
||||||
constructor(msg: string = 'User unauthorized.') {
|
constructor(msg: string = 'User unauthorized.') {
|
||||||
super(msg);
|
super(msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user