Skip to main content

Function: isGSwapError

Call Signature​

isGSwapError(value): value is AnyGSwapError

True when value is an SDK error a gswap flow can throw and, when code is given, carries exactly that code. With a code, error.params narrows to that code's params.

It recognises every GalaSDKError (instanceof), not only a GSwapSDKError: the signing, transport and wallet failures of a gswap flow come from @gala-chain/gala-core-sdk (a signer, the fetch requestor), carry a core code, and are core GalaSDKErrors. For such an error the fields are exactly a GSwapSDKError's (notFound differs only for the DEX not-found codes, which core never throws), so the narrowing holds for everything a gswap flow throws.

Parameters​

ParameterType
valueunknown

Returns​

value is AnyGSwapError

Example​

if (isGSwapError(error, 'NON_CANONICAL_PAIR')) {
t('errors.NON_CANONICAL_PAIR', error.params); // { token0, token1 }
}

Call Signature​

isGSwapError<C>(value, code): value is GSwapSDKError<C>

True when value is an SDK error a gswap flow can throw and, when code is given, carries exactly that code. With a code, error.params narrows to that code's params.

It recognises every GalaSDKError (instanceof), not only a GSwapSDKError: the signing, transport and wallet failures of a gswap flow come from @gala-chain/gala-core-sdk (a signer, the fetch requestor), carry a core code, and are core GalaSDKErrors. For such an error the fields are exactly a GSwapSDKError's (notFound differs only for the DEX not-found codes, which core never throws), so the narrowing holds for everything a gswap flow throws.

Type Parameters​

Type Parameter
C extends GSwapErrorCode

Parameters​

ParameterType
valueunknown
codeC

Returns​

value is GSwapSDKError<C>

Example​

if (isGSwapError(error, 'NON_CANONICAL_PAIR')) {
t('errors.NON_CANONICAL_PAIR', error.params); // { token0, token1 }
}