getErrorFromCode

errors · /index·function

Maps a GenericErrorKind or ApiErrorKind code to its corresponding error class, enabling reconstruction of typed errors from serialized codes.

Signature

@nordcom/commerce-errors
function getErrorFromCode(code: ApiErrorKind | GenericErrorKind): typeof ApiError | typeof GenericError;

Parameters

NameTypeDescription
codeApiErrorKind | GenericErrorKind

Returns

The error class constructor for the code, or null when the code is not recognized.

Example

const ErrorClass = getErrorFromCode(ApiErrorKind.API_UNKNOWN_SHOP_DOMAIN);
if (ErrorClass) throw new ErrorClass();

ApiErrorKind GenericErrorKind ApiError CartNotFoundError CartProviderError CartUserError ConvexOperatorTokenMintError DomainVerificationError

Sourceindex.ts:1529Edit the JSDoc directly
Metadata@nordcom/commerce-errors@0.0.0Open in GitHub ↗

On this page