Page MenuHomePhabricator

D12057.id40238.diff
No OneTemporary

D12057.id40238.diff

diff --git a/lib/shared/keyserver-utils.js b/lib/shared/keyserver-utils.js
--- a/lib/shared/keyserver-utils.js
+++ b/lib/shared/keyserver-utils.js
@@ -13,7 +13,7 @@
function useIsKeyserverURLValid(
keyserverURL?: string,
-): () => Promise<?VersionResponse> {
+): () => Promise<VersionResponse> {
const urlsToIDs: { +[keyserverID: string]: ?string } =
useSelector(urlsToIDsSelector);
@@ -53,18 +53,14 @@
return React.useCallback(async () => {
if (!keyserverURL) {
- return null;
+ throw new Error('isKeyserverURLValid called with empty URL');
}
const getVersionPromise = getVersionCall();
void dispatchActionPromise(getVersionActionTypes, getVersionPromise);
- try {
- const { versionResponses } = await getVersionPromise;
- return versionResponses[Object.keys(versionResponses)[0]];
- } catch (e) {
- return null;
- }
+ const { versionResponses } = await getVersionPromise;
+ return versionResponses[Object.keys(versionResponses)[0]];
}, [dispatchActionPromise, getVersionCall, keyserverURL]);
}
diff --git a/native/profile/add-keyserver.react.js b/native/profile/add-keyserver.react.js
--- a/native/profile/add-keyserver.react.js
+++ b/native/profile/add-keyserver.react.js
@@ -8,6 +8,7 @@
import { useIsKeyserverURLValid } from 'lib/shared/keyserver-utils.js';
import type { KeyserverInfo } from 'lib/types/keyserver-types.js';
import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js';
+import { getMessageForException } from 'lib/utils/errors.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
import type { ProfileNavigationProp } from './profile.react.js';
@@ -16,15 +17,20 @@
import type { NavigationRoute } from '../navigation/route-names.js';
import { useSelector } from '../redux/redux-utils.js';
import { useStyles, useColors } from '../themes/colors.js';
+import { AppOutOfDateAlertDetails } from '../utils/alert-messages.js';
import { useStaffCanSee } from '../utils/staff-utils.js';
type KeyserverCheckStatus =
| { +status: 'inactive' }
| { +status: 'loading' }
- | { +status: 'error' };
+ | { +status: 'error', +error: 'generic' | 'client_version_unsupported' };
const keyserverCheckStatusInactive = { status: 'inactive' };
const keyserverCheckStatusLoading = { status: 'loading' };
-const keyserverCheckStatusError = { status: 'error' };
+const keyserverCheckStatusGenericError = { status: 'error', error: 'generic' };
+const keyserverCheckStatusVersionError = {
+ status: 'error',
+ error: 'client_version_unsupported',
+};
type Props = {
+navigation: ProfileNavigationProp<'AddKeyserver'>,
@@ -59,9 +65,16 @@
}
setStatus(keyserverCheckStatusLoading);
- const keyserverVersionData = await isKeyserverURLValidCallback();
- if (!keyserverVersionData) {
- setStatus(keyserverCheckStatusError);
+ let keyserverVersionData;
+ try {
+ keyserverVersionData = await isKeyserverURLValidCallback();
+ } catch (e) {
+ const message = getMessageForException(e);
+ if (message === 'client_version_unsupported') {
+ setStatus(keyserverCheckStatusVersionError);
+ } else {
+ setStatus(keyserverCheckStatusGenericError);
+ }
return;
}
setStatus(keyserverCheckStatusInactive);
@@ -97,19 +110,20 @@
[],
);
- const showErrorMessage = status.status === 'error';
+ const { error } = status;
const errorMessage = React.useMemo(() => {
- if (!showErrorMessage) {
+ let errorText;
+ if (error === 'client_version_unsupported') {
+ errorText = AppOutOfDateAlertDetails.message;
+ } else if (error) {
+ errorText =
+ 'Cannot connect to keyserver. Please check the URL or your ' +
+ 'and try again.';
+ } else {
return null;
}
-
- return (
- <Text style={styles.errorMessage}>
- Cannot connect to keyserver. Please check the URL or your connection and
- try again.
- </Text>
- );
- }, [showErrorMessage, styles.errorMessage]);
+ return <Text style={styles.errorMessage}>{errorText}</Text>;
+ }, [error, styles.errorMessage]);
return (
<View style={styles.container}>
diff --git a/web/modals/keyserver-selection/add-keyserver-modal.react.js b/web/modals/keyserver-selection/add-keyserver-modal.react.js
--- a/web/modals/keyserver-selection/add-keyserver-modal.react.js
+++ b/web/modals/keyserver-selection/add-keyserver-modal.react.js
@@ -7,22 +7,28 @@
import { useIsKeyserverURLValid } from 'lib/shared/keyserver-utils.js';
import type { KeyserverInfo } from 'lib/types/keyserver-types.js';
import { defaultKeyserverInfo } from 'lib/types/keyserver-types.js';
+import { getMessageForException } from 'lib/utils/errors.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
import css from './add-keyserver-modal.css';
import Button, { buttonThemes } from '../../components/button.react.js';
import { useSelector } from '../../redux/redux-utils.js';
import { useStaffCanSee } from '../../utils/staff-utils.js';
+import { getVersionUnsupportedError } from '../../utils/version-utils.js';
import Input from '../input.react.js';
import Modal from '../modal.react.js';
type KeyserverCheckStatus =
| { +status: 'inactive' }
| { +status: 'loading' }
- | { +status: 'error' };
+ | { +status: 'error', +error: 'generic' | 'client_version_unsupported' };
const keyserverCheckStatusInactive = { status: 'inactive' };
const keyserverCheckStatusLoading = { status: 'loading' };
-const keyserverCheckStatusError = { status: 'error' };
+const keyserverCheckStatusGenericError = { status: 'error', error: 'generic' };
+const keyserverCheckStatusVersionError = {
+ status: 'error',
+ error: 'client_version_unsupported',
+};
function AddKeyserverModal(): React.Node {
const { popModal } = useModalContext();
@@ -55,9 +61,16 @@
}
setStatus(keyserverCheckStatusLoading);
- const keyserverVersionData = await isKeyserverURLValidCallback();
- if (!keyserverVersionData) {
- setStatus(keyserverCheckStatusError);
+ let keyserverVersionData;
+ try {
+ keyserverVersionData = await isKeyserverURLValidCallback();
+ } catch (e) {
+ const message = getMessageForException(e);
+ if (message === 'client_version_unsupported') {
+ setStatus(keyserverCheckStatusVersionError);
+ } else {
+ setStatus(keyserverCheckStatusGenericError);
+ }
return;
}
setStatus(keyserverCheckStatusInactive);
@@ -81,16 +94,18 @@
isKeyserverURLValidCallback,
]);
- const showErrorMessage = status.status === 'error';
+ const { error } = status;
const errorMessage = React.useMemo(() => {
let errorText;
- if (showErrorMessage) {
+ if (error === 'client_version_unsupported') {
+ errorText = getVersionUnsupportedError();
+ } else if (error) {
errorText =
'Cannot connect to keyserver. Please check the URL or your ' +
'connection and try again.';
}
return <div className={css.errorMessage}>{errorText}</div>;
- }, [showErrorMessage]);
+ }, [error]);
const buttonDisabled = !keyserverURL || status.status === 'loading';
const addKeyserverButton = React.useMemo(

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 12:16 AM (13 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2446656
Default Alt Text
D12057.id40238.diff (7 KB)

Event Timeline