Conform more of the codebase to strict types (#11191)
This commit is contained in:
parent
4044c2aa66
commit
8107f1d271
25 changed files with 88 additions and 57 deletions
|
@ -626,7 +626,8 @@ async function setBotPower(
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
sendError(event, err instanceof Error ? err.message : _t("Failed to send request."), err);
|
const error = err instanceof Error ? err : undefined;
|
||||||
|
sendError(event, error?.message ?? _t("Failed to send request."), error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1105,7 +1105,7 @@ export const Commands = [
|
||||||
try {
|
try {
|
||||||
cli.forceDiscardSession(roomId);
|
cli.forceDiscardSession(roomId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return reject(e.message);
|
return reject(e instanceof Error ? e.message : e);
|
||||||
}
|
}
|
||||||
return success();
|
return success();
|
||||||
},
|
},
|
||||||
|
@ -1134,7 +1134,7 @@ export const Commands = [
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return reject(e.message);
|
return reject(e instanceof Error ? e.message : e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
category: CommandCategories.advanced,
|
category: CommandCategories.advanced,
|
||||||
|
|
|
@ -20,10 +20,11 @@ import FileSaver from "file-saver";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
|
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
|
||||||
import { TrustInfo } from "matrix-js-sdk/src/crypto/backup";
|
import { TrustInfo } from "matrix-js-sdk/src/crypto/backup";
|
||||||
import { CrossSigningKeys, MatrixError, UIAFlow } from "matrix-js-sdk/src/matrix";
|
import { CrossSigningKeys, IAuthDict, MatrixError, UIAFlow } from "matrix-js-sdk/src/matrix";
|
||||||
import { IRecoveryKey } from "matrix-js-sdk/src/crypto/api";
|
import { IRecoveryKey } from "matrix-js-sdk/src/crypto/api";
|
||||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
import { UIAResponse } from "matrix-js-sdk/src/@types/uia";
|
||||||
|
|
||||||
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
|
||||||
import { _t, _td } from "../../../../languageHandler";
|
import { _t, _td } from "../../../../languageHandler";
|
||||||
|
@ -90,7 +91,7 @@ interface IState {
|
||||||
accountPasswordCorrect: boolean | null;
|
accountPasswordCorrect: boolean | null;
|
||||||
canSkip: boolean;
|
canSkip: boolean;
|
||||||
passPhraseKeySelected: string;
|
passPhraseKeySelected: string;
|
||||||
error?: string;
|
error?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -279,7 +280,9 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private doBootstrapUIAuth = async (makeRequest: (authData: any) => Promise<{}>): Promise<void> => {
|
private doBootstrapUIAuth = async (
|
||||||
|
makeRequest: (authData: IAuthDict) => Promise<UIAResponse<void>>,
|
||||||
|
): Promise<void> => {
|
||||||
if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) {
|
if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) {
|
||||||
await makeRequest({
|
await makeRequest({
|
||||||
type: "m.login.password",
|
type: "m.login.password",
|
||||||
|
@ -385,7 +388,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
|
||||||
phase: Phase.Migrate,
|
phase: Phase.Migrate,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState({ error: e });
|
this.setState({ error: true });
|
||||||
}
|
}
|
||||||
logger.error("Error bootstrapping secret storage", e);
|
logger.error("Error bootstrapping secret storage", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,11 +246,11 @@ export default class Registration extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (serverConfig !== this.latestServerConfig) return; // discard, serverConfig changed from under us
|
if (serverConfig !== this.latestServerConfig) return; // discard, serverConfig changed from under us
|
||||||
if (e.httpStatus === 401) {
|
if (e instanceof MatrixError && e.httpStatus === 401) {
|
||||||
this.setState({
|
this.setState({
|
||||||
flows: e.data.flows,
|
flows: e.data.flows,
|
||||||
});
|
});
|
||||||
} else if (e.httpStatus === 403 || e.errcode === "M_FORBIDDEN") {
|
} else if (e instanceof MatrixError && (e.httpStatus === 403 || e.errcode === "M_FORBIDDEN")) {
|
||||||
// Check for 403 or M_FORBIDDEN, Synapse used to send 403 M_UNKNOWN but now sends 403 M_FORBIDDEN.
|
// Check for 403 or M_FORBIDDEN, Synapse used to send 403 M_UNKNOWN but now sends 403 M_FORBIDDEN.
|
||||||
// At this point registration is pretty much disabled, but before we do that let's
|
// At this point registration is pretty much disabled, but before we do that let's
|
||||||
// quickly check to see if the server supports SSO instead. If it does, we'll send
|
// quickly check to see if the server supports SSO instead. If it does, we'll send
|
||||||
|
|
|
@ -60,7 +60,7 @@ export default class ChangelogDialog extends React.Component<IProps, State> {
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
this.setState({ [repo]: body.commits });
|
this.setState({ [repo]: body.commits });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ [repo]: err.message });
|
this.setState({ [repo]: err instanceof Error ? err.message : _t("Unknown error") });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ interface IState {
|
||||||
shouldLoadBackupStatus: boolean;
|
shouldLoadBackupStatus: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
backupInfo: IKeyBackupInfo | null;
|
backupInfo: IKeyBackupInfo | null;
|
||||||
error?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LogoutDialog extends React.Component<IProps, IState> {
|
export default class LogoutDialog extends React.Component<IProps, IState> {
|
||||||
|
@ -75,7 +74,6 @@ export default class LogoutDialog extends React.Component<IProps, IState> {
|
||||||
logger.log("Unable to fetch key backup status", e);
|
logger.log("Unable to fetch key backup status", e);
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
error: e,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
this.setState({
|
this.setState({
|
||||||
busy: false,
|
busy: false,
|
||||||
err: e.message,
|
err: e instanceof Error ? e.message : String(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,8 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { CrossSigningKeys } from "matrix-js-sdk/src/client";
|
import { CrossSigningKeys } from "matrix-js-sdk/src/client";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { UIAFlow } from "matrix-js-sdk/src/matrix";
|
import { AuthDict, MatrixError, UIAFlow } from "matrix-js-sdk/src/matrix";
|
||||||
|
import { UIAResponse } from "matrix-js-sdk/src/@types/uia";
|
||||||
|
|
||||||
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
|
||||||
import { _t } from "../../../../languageHandler";
|
import { _t } from "../../../../languageHandler";
|
||||||
|
@ -79,7 +80,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
|
||||||
// no keys which would be a no-op.
|
// no keys which would be a no-op.
|
||||||
logger.log("uploadDeviceSigningKeys unexpectedly succeeded without UI auth!");
|
logger.log("uploadDeviceSigningKeys unexpectedly succeeded without UI auth!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!error.data || !error.data.flows) {
|
if (!(error instanceof MatrixError) || !error.data || !error.data.flows) {
|
||||||
logger.log("uploadDeviceSigningKeys advertised no flows!");
|
logger.log("uploadDeviceSigningKeys advertised no flows!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +93,9 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private doBootstrapUIAuth = async (makeRequest: (authData: any) => Promise<{}>): Promise<void> => {
|
private doBootstrapUIAuth = async (
|
||||||
|
makeRequest: (authData: AuthDict) => Promise<UIAResponse<void>>,
|
||||||
|
): Promise<void> => {
|
||||||
if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) {
|
if (this.state.canUploadKeysWithPasswordOnly && this.state.accountPassword) {
|
||||||
await makeRequest({
|
await makeRequest({
|
||||||
type: "m.login.password",
|
type: "m.login.password",
|
||||||
|
|
|
@ -55,7 +55,7 @@ interface IState {
|
||||||
backupInfo: IKeyBackupInfo | null;
|
backupInfo: IKeyBackupInfo | null;
|
||||||
backupKeyStored: Record<string, ISecretStorageKeyInfo> | null;
|
backupKeyStored: Record<string, ISecretStorageKeyInfo> | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
loadError: string | null;
|
loadError: boolean | null;
|
||||||
restoreError: {
|
restoreError: {
|
||||||
errcode: string;
|
errcode: string;
|
||||||
} | null;
|
} | null;
|
||||||
|
@ -66,7 +66,7 @@ interface IState {
|
||||||
passPhrase: string;
|
passPhrase: string;
|
||||||
restoreType: RestoreType | null;
|
restoreType: RestoreType | null;
|
||||||
progress: {
|
progress: {
|
||||||
stage: ProgressState;
|
stage: ProgressState | string;
|
||||||
total?: number;
|
total?: number;
|
||||||
successes?: number;
|
successes?: number;
|
||||||
failures?: number;
|
failures?: number;
|
||||||
|
@ -304,7 +304,7 @@ export default class RestoreKeyBackupDialog extends React.PureComponent<IProps,
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log("Error loading backup status", e);
|
logger.log("Error loading backup status", e);
|
||||||
this.setState({
|
this.setState({
|
||||||
loadError: e,
|
loadError: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ export default class LazyRenderList<T = any> extends React.Component<IProps<T>,
|
||||||
this.state = LazyRenderList.getDerivedStateFromProps(props, {} as IState) as IState;
|
this.state = LazyRenderList.getDerivedStateFromProps(props, {} as IState) as IState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDerivedStateFromProps(props: IProps<unknown>, state: IState): Partial<IState> | null {
|
public static getDerivedStateFromProps<T>(props: IProps<T>, state: IState): Partial<IState> | null {
|
||||||
const range = LazyRenderList.getVisibleRangeFromProps(props);
|
const range = LazyRenderList.getVisibleRangeFromProps(props);
|
||||||
const intersectRange = range.expand(props.overflowMargin);
|
const intersectRange = range.expand(props.overflowMargin);
|
||||||
const renderRange = range.expand(props.overflowItems);
|
const renderRange = range.expand(props.overflowItems);
|
||||||
|
@ -105,7 +105,7 @@ export default class LazyRenderList<T = any> extends React.Component<IProps<T>,
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getVisibleRangeFromProps(props: IProps<unknown>): ItemRange {
|
private static getVisibleRangeFromProps<T>(props: IProps<T>): ItemRange {
|
||||||
const { items, itemHeight, scrollTop, height } = props;
|
const { items, itemHeight, scrollTop, height } = props;
|
||||||
const length = items ? items.length : 0;
|
const length = items ? items.length : 0;
|
||||||
const topCount = Math.min(Math.max(0, Math.floor(scrollTop / itemHeight)), length);
|
const topCount = Math.min(Math.max(0, Math.floor(scrollTop / itemHeight)), length);
|
||||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { createRef, KeyboardEventHandler } from "react";
|
import React, { createRef, KeyboardEventHandler } from "react";
|
||||||
|
import { MatrixError } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { _t } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import withValidation, { IFieldState, IValidationResult } from "./Validation";
|
import withValidation, { IFieldState, IValidationResult } from "./Validation";
|
||||||
|
@ -209,7 +210,7 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>
|
||||||
// any server error code will do,
|
// any server error code will do,
|
||||||
// either it M_NOT_FOUND or the alias is invalid somehow,
|
// either it M_NOT_FOUND or the alias is invalid somehow,
|
||||||
// in which case we don't want to show the invalid message
|
// in which case we don't want to show the invalid message
|
||||||
return !!err.errcode;
|
return err instanceof MatrixError;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
valid: () => _t("This address is available to use"),
|
valid: () => _t("This address is available to use"),
|
||||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||||
import { IAuthDict, IAuthData } from "matrix-js-sdk/src/interactive-auth";
|
import { IAuthDict, IAuthData } from "matrix-js-sdk/src/interactive-auth";
|
||||||
|
|
||||||
import { _t } from "../../../../languageHandler";
|
import { _t } from "../../../../languageHandler";
|
||||||
|
@ -42,7 +42,7 @@ export const deleteDevicesWithInteractiveAuth = async (
|
||||||
// no interactive auth needed
|
// no interactive auth needed
|
||||||
onFinished(true, undefined);
|
onFinished(true, undefined);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.httpStatus !== 401 || !error.data?.flows) {
|
if (!(error instanceof MatrixError) || error.httpStatus !== 401 || !error.data?.flows) {
|
||||||
// doesn't look like an interactive-auth failure
|
// doesn't look like an interactive-auth failure
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ export const deleteDevicesWithInteractiveAuth = async (
|
||||||
Modal.createDialog(InteractiveAuthDialog, {
|
Modal.createDialog(InteractiveAuthDialog, {
|
||||||
title: _t("Authentication"),
|
title: _t("Authentication"),
|
||||||
matrixClient: matrixClient,
|
matrixClient: matrixClient,
|
||||||
authData: error.data,
|
authData: error.data as IAuthData,
|
||||||
onFinished,
|
onFinished,
|
||||||
makeRequest: makeDeleteRequest(matrixClient, deviceIds),
|
makeRequest: makeDeleteRequest(matrixClient, deviceIds),
|
||||||
aestheticsForStagePhases: {
|
aestheticsForStagePhases: {
|
||||||
|
|
|
@ -147,7 +147,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
|
||||||
}
|
}
|
||||||
await request.accept();
|
await request.accept();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err.message);
|
logger.error("Failed to accept verification request", err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Dispatch, SetStateAction, useCallback, useEffect, useState } from "react";
|
import { Dispatch, useCallback, useEffect, useState } from "react";
|
||||||
|
|
||||||
const getValue = <T>(key: string, initialValue: T): T => {
|
const getValue = <T>(key: string, initialValue: T): T => {
|
||||||
try {
|
try {
|
||||||
|
@ -26,7 +26,7 @@ const getValue = <T>(key: string, initialValue: T): T => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hook behaving like useState but persisting the value to localStorage. Returns same as useState
|
// Hook behaving like useState but persisting the value to localStorage. Returns same as useState
|
||||||
export const useLocalStorageState = <T>(key: string, initialValue: T): [T, Dispatch<SetStateAction<T>>] => {
|
export const useLocalStorageState = <T>(key: string, initialValue: T): [T, Dispatch<T>] => {
|
||||||
const lsKey = "mx_" + key;
|
const lsKey = "mx_" + key;
|
||||||
|
|
||||||
const [value, setValue] = useState<T>(getValue(lsKey, initialValue));
|
const [value, setValue] = useState<T>(getValue(lsKey, initialValue));
|
||||||
|
@ -35,7 +35,7 @@ export const useLocalStorageState = <T>(key: string, initialValue: T): [T, Dispa
|
||||||
setValue(getValue(lsKey, initialValue));
|
setValue(getValue(lsKey, initialValue));
|
||||||
}, [lsKey, initialValue]);
|
}, [lsKey, initialValue]);
|
||||||
|
|
||||||
const _setValue: Dispatch<SetStateAction<T>> = useCallback(
|
const _setValue: Dispatch<T> = useCallback(
|
||||||
(v: T) => {
|
(v: T) => {
|
||||||
window.localStorage.setItem(lsKey, JSON.stringify(v));
|
window.localStorage.setItem(lsKey, JSON.stringify(v));
|
||||||
setValue(v);
|
setValue(v);
|
||||||
|
|
|
@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Dispatch, SetStateAction, useState } from "react";
|
import { Dispatch, useState } from "react";
|
||||||
|
|
||||||
// Hook to simplify interactions with a store-backed state values
|
// Hook to simplify interactions with a store-backed state values
|
||||||
// Returns value and method to change the state value
|
// Returns value and method to change the state value
|
||||||
export const useStateCallback = <T>(initialValue: T, callback: (v: T) => void): [T, Dispatch<SetStateAction<T>>] => {
|
export const useStateCallback = <T>(initialValue: T, callback: (v: T) => void): [T, Dispatch<T>] => {
|
||||||
const [value, setValue] = useState(initialValue);
|
const [value, setValue] = useState(initialValue);
|
||||||
const interceptSetValue = (newVal: T): void => {
|
const interceptSetValue = (newVal: T): void => {
|
||||||
setValue(newVal);
|
setValue(newVal);
|
||||||
|
|
|
@ -2765,6 +2765,7 @@
|
||||||
"Remove %(count)s messages|one": "Remove 1 message",
|
"Remove %(count)s messages|one": "Remove 1 message",
|
||||||
"Can't start voice message": "Can't start voice message",
|
"Can't start voice message": "Can't start voice message",
|
||||||
"You can't start a voice message as you are currently recording a live broadcast. Please end your live broadcast in order to start recording a voice message.": "You can't start a voice message as you are currently recording a live broadcast. Please end your live broadcast in order to start recording a voice message.",
|
"You can't start a voice message as you are currently recording a live broadcast. Please end your live broadcast in order to start recording a voice message.": "You can't start a voice message as you are currently recording a live broadcast. Please end your live broadcast in order to start recording a voice message.",
|
||||||
|
"Unknown error": "Unknown error",
|
||||||
"Unable to load commit detail: %(msg)s": "Unable to load commit detail: %(msg)s",
|
"Unable to load commit detail: %(msg)s": "Unable to load commit detail: %(msg)s",
|
||||||
"Unavailable": "Unavailable",
|
"Unavailable": "Unavailable",
|
||||||
"Changelog": "Changelog",
|
"Changelog": "Changelog",
|
||||||
|
@ -3469,7 +3470,6 @@
|
||||||
"You don't have permission": "You don't have permission",
|
"You don't have permission": "You don't have permission",
|
||||||
"This room is suggested as a good one to join": "This room is suggested as a good one to join",
|
"This room is suggested as a good one to join": "This room is suggested as a good one to join",
|
||||||
"Suggested": "Suggested",
|
"Suggested": "Suggested",
|
||||||
"Unknown error": "Unknown error",
|
|
||||||
"Select a room below first": "Select a room below first",
|
"Select a room below first": "Select a room below first",
|
||||||
"Mark as not suggested": "Mark as not suggested",
|
"Mark as not suggested": "Mark as not suggested",
|
||||||
"Mark as suggested": "Mark as suggested",
|
"Mark as suggested": "Mark as suggested",
|
||||||
|
|
|
@ -666,7 +666,9 @@ export default class SettingsStore {
|
||||||
logger.log(`--- ${handlerName}@${roomId || "<no_room>"} = ${JSON.stringify(value)}`);
|
logger.log(`--- ${handlerName}@${roomId || "<no_room>"} = ${JSON.stringify(value)}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log(
|
logger.log(
|
||||||
`--- ${handler.constructor.name}@${roomId || "<no_room>"} THREW ERROR: ${e.message}`,
|
`--- ${handler.constructor.name}@${roomId || "<no_room>"} THREW ERROR: ${
|
||||||
|
e instanceof Error ? e.message : e
|
||||||
|
}`,
|
||||||
);
|
);
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
|
@ -676,7 +678,11 @@ export default class SettingsStore {
|
||||||
const value = handler.getValue(settingName, null);
|
const value = handler.getValue(settingName, null);
|
||||||
logger.log(`--- ${handlerName}@<no_room> = ${JSON.stringify(value)}`);
|
logger.log(`--- ${handlerName}@<no_room> = ${JSON.stringify(value)}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log(`--- ${handler.constructor.name}@<no_room> THREW ERROR: ${e.message}`);
|
logger.log(
|
||||||
|
`--- ${handler.constructor.name}@<no_room> THREW ERROR: ${
|
||||||
|
e instanceof Error ? e.message : e
|
||||||
|
}`,
|
||||||
|
);
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -689,7 +695,11 @@ export default class SettingsStore {
|
||||||
const value = SettingsStore.getValue(settingName, roomId);
|
const value = SettingsStore.getValue(settingName, roomId);
|
||||||
logger.log(`--- SettingsStore#generic@${roomId || "<no_room>"} = ${JSON.stringify(value)}`);
|
logger.log(`--- SettingsStore#generic@${roomId || "<no_room>"} = ${JSON.stringify(value)}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log(`--- SettingsStore#generic@${roomId || "<no_room>"} THREW ERROR: ${e.message}`);
|
logger.log(
|
||||||
|
`--- SettingsStore#generic@${roomId || "<no_room>"} THREW ERROR: ${
|
||||||
|
e instanceof Error ? e.message : e
|
||||||
|
}`,
|
||||||
|
);
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,7 +708,9 @@ export default class SettingsStore {
|
||||||
const value = SettingsStore.getValue(settingName, null);
|
const value = SettingsStore.getValue(settingName, null);
|
||||||
logger.log(`--- SettingsStore#generic@<no_room> = ${JSON.stringify(value)}`);
|
logger.log(`--- SettingsStore#generic@<no_room> = ${JSON.stringify(value)}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log(`--- SettingsStore#generic@$<no_room> THREW ERROR: ${e.message}`);
|
logger.log(
|
||||||
|
`--- SettingsStore#generic@$<no_room> THREW ERROR: ${e instanceof Error ? e.message : e}`,
|
||||||
|
);
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -708,7 +720,11 @@ export default class SettingsStore {
|
||||||
const value = SettingsStore.getValueAt(level, settingName, roomId);
|
const value = SettingsStore.getValueAt(level, settingName, roomId);
|
||||||
logger.log(`--- SettingsStore#${level}@${roomId || "<no_room>"} = ${JSON.stringify(value)}`);
|
logger.log(`--- SettingsStore#${level}@${roomId || "<no_room>"} = ${JSON.stringify(value)}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log(`--- SettingsStore#${level}@${roomId || "<no_room>"} THREW ERROR: ${e.message}`);
|
logger.log(
|
||||||
|
`--- SettingsStore#${level}@${roomId || "<no_room>"} THREW ERROR: ${
|
||||||
|
e instanceof Error ? e.message : e
|
||||||
|
}`,
|
||||||
|
);
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,7 +733,11 @@ export default class SettingsStore {
|
||||||
const value = SettingsStore.getValueAt(level, settingName, null);
|
const value = SettingsStore.getValueAt(level, settingName, null);
|
||||||
logger.log(`--- SettingsStore#${level}@<no_room> = ${JSON.stringify(value)}`);
|
logger.log(`--- SettingsStore#${level}@<no_room> = ${JSON.stringify(value)}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log(`--- SettingsStore#${level}@$<no_room> THREW ERROR: ${e.message}`);
|
logger.log(
|
||||||
|
`--- SettingsStore#${level}@$<no_room> THREW ERROR: ${
|
||||||
|
e instanceof Error ? e.message : e
|
||||||
|
}`,
|
||||||
|
);
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ export default class MultiInviter {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// The error handling during the invitation process covers any API.
|
// The error handling during the invitation process covers any API.
|
||||||
// Some errors must to me mapped from profile API errors to more specific ones to avoid collisions.
|
// Some errors must to me mapped from profile API errors to more specific ones to avoid collisions.
|
||||||
switch (err.errcode) {
|
switch (err instanceof MatrixError ? err.errcode : err) {
|
||||||
case "M_FORBIDDEN":
|
case "M_FORBIDDEN":
|
||||||
throw new MatrixError({ errcode: "M_PROFILE_UNDISCLOSED" });
|
throw new MatrixError({ errcode: "M_PROFILE_UNDISCLOSED" });
|
||||||
case "M_NOT_FOUND":
|
case "M_NOT_FOUND":
|
||||||
|
|
|
@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IAuthDict } from "matrix-js-sdk/src/interactive-auth";
|
import { AuthDict } from "matrix-js-sdk/src/interactive-auth";
|
||||||
import { UIAResponse } from "matrix-js-sdk/src/@types/uia";
|
import { UIAResponse } from "matrix-js-sdk/src/@types/uia";
|
||||||
|
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
import InteractiveAuthDialog, { InteractiveAuthDialogProps } from "../components/views/dialogs/InteractiveAuthDialog";
|
import InteractiveAuthDialog, { InteractiveAuthDialogProps } from "../components/views/dialogs/InteractiveAuthDialog";
|
||||||
|
|
||||||
type FunctionWithUIA<R, A> = (auth?: IAuthDict | null, ...args: A[]) => Promise<UIAResponse<R>>;
|
type FunctionWithUIA<R, A> = (auth?: AuthDict, ...args: A[]) => Promise<UIAResponse<R>>;
|
||||||
|
|
||||||
export function wrapRequestWithDialog<R, A = any>(
|
export function wrapRequestWithDialog<R, A = any>(
|
||||||
requestFunction: FunctionWithUIA<R, A>,
|
requestFunction: FunctionWithUIA<R, A>,
|
||||||
|
@ -29,7 +29,7 @@ export function wrapRequestWithDialog<R, A = any>(
|
||||||
return async function (...args): Promise<R> {
|
return async function (...args): Promise<R> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const boundFunction = requestFunction.bind(opts.matrixClient) as FunctionWithUIA<R, A>;
|
const boundFunction = requestFunction.bind(opts.matrixClient) as FunctionWithUIA<R, A>;
|
||||||
boundFunction(null, ...args)
|
boundFunction(undefined, ...args)
|
||||||
.then((res) => resolve(res as R))
|
.then((res) => resolve(res as R))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (error.httpStatus !== 401 || !error.data?.flows) {
|
if (error.httpStatus !== 401 || !error.data?.flows) {
|
||||||
|
@ -40,7 +40,7 @@ export function wrapRequestWithDialog<R, A = any>(
|
||||||
Modal.createDialog(InteractiveAuthDialog, {
|
Modal.createDialog(InteractiveAuthDialog, {
|
||||||
...opts,
|
...opts,
|
||||||
authData: error.data,
|
authData: error.data,
|
||||||
makeRequest: (authData: IAuthDict | null) => boundFunction(authData, ...args),
|
makeRequest: (authData: AuthDict) => boundFunction(authData, ...args),
|
||||||
onFinished: (success, result) => {
|
onFinished: (success, result) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
resolve(result as R);
|
resolve(result as R);
|
||||||
|
|
|
@ -17,8 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { fireEvent, render, screen, waitForElementToBeRemoved } from "@testing-library/react";
|
import { fireEvent, render, screen, waitForElementToBeRemoved } from "@testing-library/react";
|
||||||
import { createClient, MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { createClient, MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||||
import { MatrixError } from "matrix-js-sdk/src/http-api/errors";
|
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
import fetchMock from "fetch-mock-jest";
|
import fetchMock from "fetch-mock-jest";
|
||||||
|
|
||||||
|
@ -26,7 +25,10 @@ import SdkConfig, { DEFAULTS } from "../../../../src/SdkConfig";
|
||||||
import { mkServerConfig, mockPlatformPeg, unmockPlatformPeg } from "../../../test-utils";
|
import { mkServerConfig, mockPlatformPeg, unmockPlatformPeg } from "../../../test-utils";
|
||||||
import Registration from "../../../../src/components/structures/auth/Registration";
|
import Registration from "../../../../src/components/structures/auth/Registration";
|
||||||
|
|
||||||
jest.mock("matrix-js-sdk/src/matrix");
|
jest.mock("matrix-js-sdk/src/matrix", () => ({
|
||||||
|
...jest.requireActual("matrix-js-sdk/src/matrix"),
|
||||||
|
createClient: jest.fn(),
|
||||||
|
}));
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
|
|
||||||
describe("Registration", function () {
|
describe("Registration", function () {
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||||
import { Preset, Visibility } from "matrix-js-sdk/src/matrix";
|
import { MatrixError, Preset, Visibility } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import CreateRoomDialog from "../../../../src/components/views/dialogs/CreateRoomDialog";
|
import CreateRoomDialog from "../../../../src/components/views/dialogs/CreateRoomDialog";
|
||||||
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils";
|
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils";
|
||||||
|
@ -29,7 +29,7 @@ describe("<CreateRoomDialog />", () => {
|
||||||
getClientWellKnown: jest.fn(),
|
getClientWellKnown: jest.fn(),
|
||||||
doesServerForceEncryptionForPreset: jest.fn(),
|
doesServerForceEncryptionForPreset: jest.fn(),
|
||||||
// make every alias available
|
// make every alias available
|
||||||
getRoomIdForAlias: jest.fn().mockRejectedValue({ errcode: "M_NOT_FOUND" }),
|
getRoomIdForAlias: jest.fn().mockRejectedValue(new MatrixError({ errcode: "M_NOT_FOUND" })),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getE2eeEnableToggleInputElement = () => screen.getByLabelText("Enable end-to-end encryption");
|
const getE2eeEnableToggleInputElement = () => screen.getByLabelText("Enable end-to-end encryption");
|
||||||
|
|
|
@ -131,7 +131,7 @@ describe("InteractiveAuthDialog", function () {
|
||||||
const successfulResult = { test: 1 };
|
const successfulResult = { test: 1 };
|
||||||
const makeRequest = jest
|
const makeRequest = jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockRejectedValueOnce(new MatrixError({ data: { flows: [{ stages: ["m.login.sso"] }] } }, 401))
|
.mockRejectedValueOnce(new MatrixError({ flows: [{ stages: ["m.login.sso"] }] }, 401))
|
||||||
.mockResolvedValue(successfulResult);
|
.mockResolvedValue(successfulResult);
|
||||||
|
|
||||||
mockClient.credentials = { userId: "@user:id" };
|
mockClient.credentials = { userId: "@user:id" };
|
||||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { UIAFlow } from "matrix-js-sdk/src/matrix";
|
import { MatrixError, UIAFlow } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { deleteDevicesWithInteractiveAuth } from "../../../../../src/components/views/settings/devices/deleteDevices";
|
import { deleteDevicesWithInteractiveAuth } from "../../../../../src/components/views/settings/devices/deleteDevices";
|
||||||
import Modal from "../../../../../src/Modal";
|
import Modal from "../../../../../src/Modal";
|
||||||
|
@ -30,7 +30,7 @@ describe("deleteDevices()", () => {
|
||||||
|
|
||||||
const modalSpy = jest.spyOn(Modal, "createDialog") as jest.SpyInstance;
|
const modalSpy = jest.spyOn(Modal, "createDialog") as jest.SpyInstance;
|
||||||
|
|
||||||
const interactiveAuthError = { httpStatus: 401, data: { flows: [] as UIAFlow[] } };
|
const interactiveAuthError = new MatrixError({ flows: [] as UIAFlow[] }, 401);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
|
|
@ -31,6 +31,7 @@ import {
|
||||||
UNSTABLE_MSC3882_CAPABILITY,
|
UNSTABLE_MSC3882_CAPABILITY,
|
||||||
CryptoApi,
|
CryptoApi,
|
||||||
DeviceVerificationStatus,
|
DeviceVerificationStatus,
|
||||||
|
MatrixError,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
|
|
||||||
|
@ -722,10 +723,12 @@ describe("<SessionManagerTab />", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("other devices", () => {
|
describe("other devices", () => {
|
||||||
const interactiveAuthError = {
|
const interactiveAuthError = new MatrixError(
|
||||||
httpStatus: 401,
|
{
|
||||||
data: { flows: [{ stages: ["m.login.password"] }] },
|
flows: [{ stages: ["m.login.password"] }],
|
||||||
};
|
},
|
||||||
|
401,
|
||||||
|
);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockClient.deleteMultipleDevices.mockReset();
|
mockClient.deleteMultipleDevices.mockReset();
|
||||||
|
|
|
@ -32,8 +32,8 @@ const MXID3 = "@user3:server";
|
||||||
|
|
||||||
const MXID_PROFILE_STATES: Record<string, Promise<any>> = {
|
const MXID_PROFILE_STATES: Record<string, Promise<any>> = {
|
||||||
[MXID1]: Promise.resolve({}),
|
[MXID1]: Promise.resolve({}),
|
||||||
[MXID2]: Promise.reject({ errcode: "M_FORBIDDEN" }),
|
[MXID2]: Promise.reject(new MatrixError({ errcode: "M_FORBIDDEN" })),
|
||||||
[MXID3]: Promise.reject({ errcode: "M_NOT_FOUND" }),
|
[MXID3]: Promise.reject(new MatrixError({ errcode: "M_NOT_FOUND" })),
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock("../../src/Modal", () => ({
|
jest.mock("../../src/Modal", () => ({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue