Skip to content

Commit

Permalink
Bugfix/live 5056 error mapping not found entity (#5315)
Browse files Browse the repository at this point in the history
* fix(common, llm, lld): better wording of not found entity error

* chore: changeset

* fix(common/manager api): remap 404 error in get_firmware_version

* fix(lld, llm): wording capitalisation

* fix(llm/pairing/RenderError): properly render wrong provider error

* refactor(common/manager/api): clearer code + remove 4 year old FIXME

* fix(common/manager/api): remove bad practice of checking error message
  • Loading branch information
ofreyssinet-ledger authored and sshmaxime committed Nov 9, 2023
1 parent 415c63f commit 63f4509
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changeset/swift-pianos-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

Improve wording of "not found entity" error
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5166,8 +5166,8 @@
"description": "Please update your devices Firmware to the latest version to access this feature"
},
"FirmwareNotRecognized": {
"title": "Device firmware is not recognized",
"description": "Please contact Ledger Support"
"title": "Invalid Provider",
"description": "You have to change \"My Ledger provider\" setting. To change it, open Ledger Live \"Settings\", select \"Experimental features\", and then select a different provider."
},
"HardResetFail": {
"title": "Sorry, could not reset",
Expand Down
4 changes: 4 additions & 0 deletions apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@
},
"InvalidMemoICP": {
"title": "Memo is required to be a number"
},
"FirmwareNotRecognized": {
"title": "Invalid Provider",
"description": "You have to change \"My Ledger provider\" setting. To change it, open Ledger Live \"Settings\", select \"Experimental features\", and then select a different provider."
}
},
"crash": {
Expand Down
17 changes: 7 additions & 10 deletions apps/ledger-live-mobile/src/screens/PairDevices/RenderError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
HwTransportError,
HwTransportErrorType,
PeerRemovedPairing,
FirmwareNotRecognized,
} from "@ledgerhq/errors";
import { Flex, Button, IconsLegacy } from "@ledgerhq/native-ui";
import { useTheme } from "@react-navigation/native";
Expand Down Expand Up @@ -38,7 +39,9 @@ const hitSlop = {
function RenderError({ error, status, onBypassGenuine, onRetry }: Props) {
const { colors } = useTheme();
const isPairingStatus = status === "pairing";
const isFirmwareNotRecognized = error instanceof FirmwareNotRecognized;
const isGenuineCheckStatus = status === "genuinecheck";
const isGenuineCheckSkippableError = isGenuineCheckStatus && !isFirmwareNotRecognized;
const isBrokenPairing = error instanceof PeerRemovedPairing;

const url = isBrokenPairing
Expand Down Expand Up @@ -74,7 +77,7 @@ function RenderError({ error, status, onBypassGenuine, onRetry }: Props) {
const outerError =
isPairingStatus && !isBrokenPairing
? new PairingFailed()
: isGenuineCheckStatus
: isGenuineCheckSkippableError
? new GenuineCheckFailed()
: null;

Expand Down Expand Up @@ -107,18 +110,12 @@ function RenderError({ error, status, onBypassGenuine, onRetry }: Props) {
) : (
<>
<Flex mt={30} flexDirection={"row"}>
<Button
flex={1}
iconPosition="left"
Icon={IconsLegacy.ExternalLinkMedium}
type="main"
onPress={onRetry}
>
<Button flex={1} iconPosition="left" type="main" onPress={onRetry}>
<Trans i18nKey="common.retry" />
</Button>
</Flex>

{isGenuineCheckStatus ? (
{isGenuineCheckSkippableError ? (
<Touchable
event="PairDevicesBypassGenuine"
onPress={onBypassGenuine}
Expand All @@ -136,7 +133,7 @@ function RenderError({ error, status, onBypassGenuine, onRetry }: Props) {
</>
)}
</Flex>
{isGenuineCheckStatus ? (
{isGenuineCheckSkippableError ? (
<Flex height={48}>
<HelpLink style={styles.linkContainerGenuine} />
</Flex>
Expand Down
11 changes: 8 additions & 3 deletions libs/ledger-live-common/src/manager/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ const getCurrentFirmware: (input: {
version_name: input.version,
provider: input.provider,
},
}).catch(error => {
const status = error?.status || error?.response?.status;

if (status === 404) throw new FirmwareNotRecognized();

throw error;
});
return data;
},
Expand Down Expand Up @@ -457,13 +463,12 @@ const getDeviceVersion: (targetId: string | number, provider: number) => Promise
target_id: targetId,
},
}).catch(error => {
const status = error && (error.status || (error.response && error.response.status)); // FIXME LLD is doing error remapping already. we probably need to move the remapping in live-common
const status = error?.status || error?.response?.status;

if (status === 404) {
if (status === 404)
throw new FirmwareNotRecognized("manager api did not recognize targetId=" + targetId, {
targetId,
});
}

throw error;
});
Expand Down

0 comments on commit 63f4509

Please sign in to comment.