Skip to content

Commit

Permalink
fix(llm): triggering proper error on CLS mobile disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
fAnselmi-Ledger committed Oct 21, 2024
1 parent 2a9b922 commit b89d1e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/tame-brooms-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"live-mobile": patch
"@ledgerhq/live-common": patch
---

Triggering proper errors on CLS
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,19 @@ const CustomImageDeviceAction: React.FC<Props & { remountMe: () => void }> = ({
[dispatch, onResult],
);

const { error, imageCommitRequested, imageLoadRequested, loadingImage, progress } = status;
const {
error: CLSError,
imageCommitRequested,
imageLoadRequested,
loadingImage,
progress,
} = status;
const [error, setError] = useState<null | Error>(null);
useEffect(() => {
if (CLSError) {
setError(CLSError);
}
}, [CLSError]);
const isError = !!error;
const isRefusedOnStaxError =
(error as unknown) instanceof ImageLoadRefusedOnDevice ||
Expand Down
15 changes: 11 additions & 4 deletions libs/ledger-live-common/src/hw/customLockScreenLoad.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Observable, from, of, throwError } from "rxjs";
import { catchError, concatMap, delay, mergeMap } from "rxjs/operators";
import { catchError, concatMap, delay, mergeMap, timeout } from "rxjs/operators";
import {
DeviceOnDashboardExpected,
ManagerNotEnoughSpaceError,
StatusCodes,
TransportError,
TransportStatusError,
DisconnectedDevice,
} from "@ledgerhq/errors";
import { getDeviceModel } from "@ledgerhq/devices";

Expand Down Expand Up @@ -74,9 +75,7 @@ export default function loadImage({ deviceId, request }: Input): Observable<Load
const sub = withDevice(deviceId)(
transport =>
new Observable(subscriber => {
const timeoutSub = of<LoadImageEvent>({
type: "unresponsiveDevice",
})
const timeoutSub = of<LoadImageEvent>({ type: "unresponsiveDevice" })
.pipe(delay(1000))
.subscribe(e => subscriber.next(e));

Expand Down Expand Up @@ -213,6 +212,14 @@ export default function loadImage({ deviceId, request }: Input): Observable<Load
sub.unsubscribe();
};
}),
).pipe(
timeout(5000),
catchError(err => {
if (err.name === "TimeoutError") {
return throwError(() => new DisconnectedDevice());
}
return throwError(() => err);
}),
);

return sub as Observable<LoadImageEvent>;
Expand Down

0 comments on commit b89d1e1

Please sign in to comment.