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:
Anton Nikolaev
2021-06-02 11:29:11 -07:00
committed by Facebook GitHub Bot
parent fff489091e
commit b7d7326bae
2 changed files with 23 additions and 23 deletions

View File

@@ -7,13 +7,7 @@
* @format
*/
import React, {
cloneElement,
useState,
useCallback,
useMemo,
useEffect,
} from 'react';
import React, {cloneElement, useState, useCallback, useMemo} from 'react';
import {Button, Divider, Badge, Tooltip, Avatar, Popover} from 'antd';
import {
MobileFilled,
@@ -50,7 +44,6 @@ import {showEmulatorLauncher} from './appinspect/LaunchEmulator';
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
import {setStaticView, StaticView} from '../reducers/connections';
import {getInstance} from '../fb-stubs/Logger';
import {getUser} from '../fb-stubs/user';
import {SandyRatingButton} from '../chrome/RatingButton';
import {filterNotifications} from './notification/notificationUtils';
import {useMemoize} from 'flipper-plugin';
@@ -58,7 +51,6 @@ import isProduction from '../utils/isProduction';
import NetworkGraph from '../chrome/NetworkGraph';
import FpsGraph from '../chrome/FpsGraph';
import UpdateIndicator from '../chrome/UpdateIndicator';
import {UserNotSignedInError, UserUnauthorizedError} from '../utils/errors';
const LeftRailButtonElem = styled(Button)<{kind?: 'small'}>(({kind}) => ({
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 ? (
<Popover
content={

View File

@@ -9,6 +9,20 @@
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 {
constructor(msg: string) {
super(msg);
@@ -17,6 +31,14 @@ export class CancelledPromiseError extends Error {
name: 'CancelledPromiseError';
}
export class ConnectivityError extends Error {
constructor(msg: string) {
super(msg);
this.name = 'ConnectivityError';
}
name: 'ConnectivityError';
}
export class UserUnauthorizedError extends Error {
constructor(msg: string = 'User unauthorized.') {
super(msg);