File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -817,7 +817,7 @@ export class HyperLiquidProvider implements PerpsProvider {
817817 completeInFlight ( ) ;
818818 } catch ( error ) {
819819 // If keyring is locked, don't cache so it retries when unlocked
820- if ( ensureError ( error ) . message === PERPS_ERROR_CODES . KEYRING_LOCKED ) {
820+ if ( isKeyringLockedError ( error ) ) {
821821 this . #deps. debugLogger . log (
822822 '[ensureUnifiedAccountEnabled] Keyring locked, will retry later' ,
823823 ) ;
Original file line number Diff line number Diff line change 44 */
55import { hasProperty } from '@metamask/utils' ;
66
7+ import { PERPS_ERROR_CODES } from '../perpsErrorCodes' ;
8+
79/**
810 * Detects expected cancellation/abort errors that should not be reported to Sentry.
911 * These occur during normal navigation or view teardown when in-flight fetch requests
@@ -23,6 +25,30 @@ export function isAbortError(error: unknown): boolean {
2325 return false ;
2426}
2527
28+ /**
29+ * Detects keyring-locked errors, including SDK-wrapped errors that preserve the
30+ * original error in `cause`.
31+ *
32+ * @param error - The error to check.
33+ * @returns True if any error in the cause chain is KEYRING_LOCKED.
34+ */
35+ export function isKeyringLockedError ( error : unknown ) : boolean {
36+ let current : unknown = error ;
37+ const seen = new Set < unknown > ( ) ;
38+
39+ while ( current instanceof Error && ! seen . has ( current ) ) {
40+ seen . add ( current ) ;
41+
42+ if ( current . message === PERPS_ERROR_CODES . KEYRING_LOCKED ) {
43+ return true ;
44+ }
45+
46+ current = ( current as { cause ?: unknown } ) . cause ;
47+ }
48+
49+ return false ;
50+ }
51+
2652/**
2753 * Ensures we have a proper Error object for logging.
2854 * Converts unknown/string errors to proper Error instances.
You can’t perform that action at this time.
0 commit comments