-
-
Notifications
You must be signed in to change notification settings - Fork 828
Properly translate errors in ChangePassword.tsx
so they show up translated to the user but not in our logs
#10615
Changes from 4 commits
32ece81
07a0a74
c62c6c9
7786dd1
a7c2fe4
772c15d
329b868
93f238b
e0fbd73
1f8bd91
fc70a22
798bb19
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 |
---|---|---|
|
@@ -21,9 +21,9 @@ import { SERVICE_TYPES } from "matrix-js-sdk/src/service-types"; | |
import { IThreepid } from "matrix-js-sdk/src/@types/threepids"; | ||
import { logger } from "matrix-js-sdk/src/logger"; | ||
import { IDelegatedAuthConfig, M_AUTHENTICATION } from "matrix-js-sdk/src/matrix"; | ||
import { MatrixError } from "matrix-js-sdk/src/matrix"; | ||
import { HTTPError } from "matrix-js-sdk/src/matrix"; | ||
|
||
import { _t } from "../../../../../languageHandler"; | ||
import { UserFriendlyError, _t } from "../../../../../languageHandler"; | ||
import ProfileSettings from "../../ProfileSettings"; | ||
import * as languageHandler from "../../../../../languageHandler"; | ||
import SettingsStore from "../../../../../settings/SettingsStore"; | ||
|
@@ -43,7 +43,7 @@ import Spinner from "../../../elements/Spinner"; | |
import { SettingLevel } from "../../../../../settings/SettingLevel"; | ||
import { UIFeature } from "../../../../../settings/UIFeature"; | ||
import { ActionPayload } from "../../../../../dispatcher/payloads"; | ||
import ErrorDialog from "../../../dialogs/ErrorDialog"; | ||
import ErrorDialog, { extractErrorMessageFromError } from "../../../dialogs/ErrorDialog"; | ||
import AccountPhoneNumbers from "../../account/PhoneNumbers"; | ||
import AccountEmailAddresses from "../../account/EmailAddresses"; | ||
import DiscoveryEmailAddresses from "../../discovery/EmailAddresses"; | ||
|
@@ -253,18 +253,37 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta | |
PlatformPeg.get()?.setSpellCheckEnabled(spellCheckEnabled); | ||
}; | ||
|
||
private onPasswordChangeError = (err: { error: string } & MatrixError): void => { | ||
// TODO: Figure out a design that doesn't involve replacing the current dialog | ||
let errMsg = err.error || err.message || ""; | ||
if (err.httpStatus === 403) { | ||
errMsg = _t("Failed to change password. Is your password correct?"); | ||
} else if (!errMsg) { | ||
errMsg += ` (HTTP status ${err.httpStatus})`; | ||
private onPasswordChangeError = (err: Error): void => { | ||
logger.error("Failed to change password: " + err); | ||
|
||
let underlyingError = err; | ||
if (err instanceof UserFriendlyError && err.cause instanceof Error) { | ||
underlyingError = err.cause; | ||
} | ||
logger.error("Failed to change password: " + errMsg); | ||
|
||
const errorMessage = extractErrorMessageFromError( | ||
err, | ||
_t("Unknown password change error (%(stringifiedError)s)", { | ||
stringifiedError: String(err), | ||
}), | ||
); | ||
|
||
let errorMessageToDisplay; | ||
if (underlyingError instanceof HTTPError && underlyingError.httpStatus === 403) { | ||
errorMessageToDisplay = _t("Failed to change password. Is your password correct?"); | ||
} else if (underlyingError instanceof HTTPError) { | ||
errorMessageToDisplay = _t("%(errorMessage)s (HTTP status %(httpStatus)s)", { | ||
errorMessage, | ||
httpStatus: underlyingError.httpStatus, | ||
}); | ||
} else { | ||
errorMessageToDisplay = errorMessage; | ||
} | ||
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. What would you think about doing something along the lines of:
I'm not completely sold on whether the nested if is better than what you have, but I'm a fan of being able to get rid of the last else with the initial assignment of 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. Both are 🤷 type of problems to me in this case. A bigger better change would be to remove the
I've updated to do this ⏩ |
||
|
||
// TODO: Figure out a design that doesn't involve replacing the current dialog | ||
Modal.createDialog(ErrorDialog, { | ||
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. Remaining strict Typescript failures are unlrelated to this PR and the problem is generally tracked by element-hq/element-web#24899 |
||
title: _t("Error"), | ||
description: errMsg, | ||
title: _t("Error changing password"), | ||
description: errorMessageToDisplay, | ||
}); | ||
}; | ||
|
||
|
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.
SonarCloud coverage not happy with these files not tested at all but it's not something I'm going to invest in now.
Will need an exception here