From 55a0e32492f489136ffbb9ceebbfc90ff356f748 Mon Sep 17 00:00:00 2001 From: Daniel Kift Date: Tue, 23 Dec 2025 14:02:15 +0000 Subject: [PATCH] use consistent error code case --- .../checkout-sheet-kit/src/errors.d.ts | 39 ++++++++++--------- .../tests/CheckoutError.test.tsx | 4 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/modules/@shopify/checkout-sheet-kit/src/errors.d.ts b/modules/@shopify/checkout-sheet-kit/src/errors.d.ts index 6739c7d7..bd74fdc2 100644 --- a/modules/@shopify/checkout-sheet-kit/src/errors.d.ts +++ b/modules/@shopify/checkout-sheet-kit/src/errors.d.ts @@ -32,32 +32,32 @@ export enum CheckoutErrorCode { /** * The app authentication payload passed could not be decoded. */ - invalidPayload = 'invalid_payload', + invalidPayload = 'INVALID_PAYLOAD', /** * The app authentication JWT signature or encrypted token signature was invalid. */ - invalidSignature = 'invalid_signature', + invalidSignature = 'INVALID_SIGNATURE', /** * The app authentication access token was not valid for the shop. */ - notAuthorized = 'not_authorized', + notAuthorized = 'NOT_AUTHORIZED', /** * The provided app authentication payload has expired. */ - payloadExpired = 'payload_expired', + payloadExpired = 'PAYLOAD_EXPIRED', /** * The buyer must be logged in to a customer account to proceed with checkout. */ - customerAccountRequired = 'customer_account_required', + customerAccountRequired = 'CUSTOMER_ACCOUNT_REQUIRED', /** * The storefront requires a password to access checkout. */ - storefrontPasswordRequired = 'storefront_password_required', + storefrontPasswordRequired = 'STOREFRONT_PASSWORD_REQUIRED', // ============================================================================ // Cart errors @@ -66,12 +66,12 @@ export enum CheckoutErrorCode { /** * The cart associated with the checkout has already been completed. */ - cartCompleted = 'cart_completed', + cartCompleted = 'CART_COMPLETED', /** * The cart is invalid or no longer exists. */ - invalidCart = 'invalid_cart', + invalidCart = 'INVALID_CART', // ============================================================================ // Client errors @@ -80,22 +80,22 @@ export enum CheckoutErrorCode { /** * Checkout preloading has been temporarily disabled via killswitch. */ - killswitchEnabled = 'killswitch_enabled', + killswitchEnabled = 'KILLSWITCH_ENABLED', /** * An unrecoverable error occurred during checkout. */ - unrecoverableFailure = 'unrecoverable_failure', + unrecoverableFailure = 'UNRECOVERABLE_FAILURE', /** * A policy violation was detected during checkout. */ - policyViolation = 'policy_violation', + policyViolation = 'POLICY_VIOLATION', /** * An error occurred processing a vaulted payment method. */ - vaultedPaymentError = 'vaulted_payment_error', + vaultedPaymentError = 'VAULTED_PAYMENT_ERROR', // ============================================================================ // Internal errors @@ -104,27 +104,27 @@ export enum CheckoutErrorCode { /** * A client-side error occurred in the SDK. */ - clientError = 'client_error', + clientError = 'CLIENT_ERROR', /** * An HTTP error occurred while communicating with the checkout. */ - httpError = 'http_error', + httpError = 'HTTP_ERROR', /** * Failed to send a message to the checkout bridge. */ - sendingBridgeEventError = 'error_sending_message', + errorSendingMessage = 'ERROR_SENDING_MESSAGE', /** * Failed to receive a message from the checkout bridge. */ - receivingBridgeEventError = 'error_receiving_message', + errorReceivingMessage = 'ERROR_RECEIVING_MESSAGE', /** * The WebView render process has terminated unexpectedly (Android only). */ - renderProcessGone = 'render_process_gone', + renderProcessGone = 'RENDER_PROCESS_GONE', // ============================================================================ // Fallback @@ -133,7 +133,7 @@ export enum CheckoutErrorCode { /** * An unknown or unrecognized error code was received. */ - unknown = 'unknown', + unknown = 'UNKNOWN', } export enum CheckoutNativeErrorType { @@ -147,13 +147,14 @@ export enum CheckoutNativeErrorType { /** * Maps a native error code string to a CheckoutErrorCode enum value. + * Handles both SCREAMING_SNAKE_CASE and snake_case formats for compatibility. */ function getCheckoutErrorCode(code: string | undefined): CheckoutErrorCode { if (!code) { return CheckoutErrorCode.unknown; } - const normalizedCode = code.toLowerCase(); + const normalizedCode = code.toUpperCase(); const codeKey = Object.keys(CheckoutErrorCode).find( key => CheckoutErrorCode[key as keyof typeof CheckoutErrorCode] === normalizedCode, diff --git a/modules/@shopify/checkout-sheet-kit/tests/CheckoutError.test.tsx b/modules/@shopify/checkout-sheet-kit/tests/CheckoutError.test.tsx index aa7ef4e7..bc5beff5 100644 --- a/modules/@shopify/checkout-sheet-kit/tests/CheckoutError.test.tsx +++ b/modules/@shopify/checkout-sheet-kit/tests/CheckoutError.test.tsx @@ -375,7 +375,7 @@ describe('Checkout Component - Error Events', () => { nativeComponent.props.onError({ nativeEvent: { __typename: 'InternalError', - code: 'error_sending_message', + code: 'ERROR_SENDING_MESSAGE', message: 'Failed to send bridge message', recoverable: false, }, @@ -386,7 +386,7 @@ describe('Checkout Component - Error Events', () => { expect(error).toBeInstanceOf(InternalError); expect(error).toMatchObject({ - code: CheckoutErrorCode.sendingBridgeEventError, + code: CheckoutErrorCode.errorSendingMessage, message: 'Failed to send bridge message', recoverable: false, name: 'InternalError',