From 1c3ed3563d3a755410be8d358d91e068d714a39c Mon Sep 17 00:00:00 2001 From: Andrea Rampin Date: Tue, 23 Jan 2024 10:57:10 +1100 Subject: [PATCH] feat: WT-2076 - expose root raw error (#1385) --- .../sdk/src/availability/availability.ts | 5 +- .../sdk/src/balances/balances.test.ts | 2 +- .../checkout/sdk/src/balances/balances.ts | 4 +- .../sdk/src/config/remoteConfigFetcher.ts | 10 +++- packages/checkout/sdk/src/connect/connect.ts | 1 + .../checkout/sdk/src/errors/checkoutError.ts | 6 ++- packages/checkout/sdk/src/network/network.ts | 1 + .../sdk/src/provider/validateProvider.ts | 1 + packages/checkout/sdk/src/sdk.ts | 10 ++-- .../smartCheckout/actions/signActions.test.ts | 12 ++--- .../src/smartCheckout/actions/signActions.ts | 12 ++--- .../src/smartCheckout/allowance/erc20.test.ts | 21 ++++----- .../sdk/src/smartCheckout/allowance/erc20.ts | 6 +-- .../smartCheckout/allowance/erc721.test.ts | 46 +++++++++---------- .../sdk/src/smartCheckout/allowance/erc721.ts | 19 ++++++-- .../balanceCheck/balanceCheck.ts | 6 ++- .../sdk/src/smartCheckout/buy/buy.test.ts | 11 ++--- .../checkout/sdk/src/smartCheckout/buy/buy.ts | 8 ++-- .../src/smartCheckout/cancel/cancel.test.ts | 6 +-- .../sdk/src/smartCheckout/cancel/cancel.ts | 2 +- .../src/smartCheckout/gas/gasCalculator.ts | 1 + .../bridge/getBridgeFeeEstimate.test.ts | 2 +- .../routing/bridge/getBridgeFeeEstimate.ts | 2 +- .../routing/routingCalculator.test.ts | 3 +- .../routing/routingCalculator.ts | 2 +- .../sdk/src/smartCheckout/sell/sell.test.ts | 24 ++++------ .../sdk/src/smartCheckout/sell/sell.ts | 4 +- .../sdk/src/transaction/transaction.ts | 4 ++ 28 files changed, 116 insertions(+), 115 deletions(-) diff --git a/packages/checkout/sdk/src/availability/availability.ts b/packages/checkout/sdk/src/availability/availability.ts index 13cb8c376a..12fcb4098f 100644 --- a/packages/checkout/sdk/src/availability/availability.ts +++ b/packages/checkout/sdk/src/availability/availability.ts @@ -23,10 +23,10 @@ export const availabilityService = ( try { response = await axios.post(`${postEndpoint()}/v1/availability/checkout/swap`); - } catch (error: any) { + } catch (err: any) { // The request was made and the server responded with a status code // that falls out of the range of 2xx - response = error.response; + response = err.response; // If 403 then the service is geo-blocked if (response.status === 403) return false; @@ -34,6 +34,7 @@ export const availabilityService = ( throw new CheckoutError( `Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR, + { error: err }, ); } diff --git a/packages/checkout/sdk/src/balances/balances.test.ts b/packages/checkout/sdk/src/balances/balances.test.ts index 85fd49b148..b8e2af3213 100644 --- a/packages/checkout/sdk/src/balances/balances.test.ts +++ b/packages/checkout/sdk/src/balances/balances.test.ts @@ -744,7 +744,7 @@ describe('balances', () => { expect(message).toEqual(testCase.expectedErrorMessage); expect(type).toEqual(CheckoutErrorType.GET_INDEXER_BALANCE_ERROR); - expect(data).toEqual({ + expect(data.error).toEqual({ code: HttpStatusCode.Forbidden, message: testCase.errorMessage, }); diff --git a/packages/checkout/sdk/src/balances/balances.ts b/packages/checkout/sdk/src/balances/balances.ts index 9297a32017..5382ffd371 100644 --- a/packages/checkout/sdk/src/balances/balances.ts +++ b/packages/checkout/sdk/src/balances/balances.ts @@ -149,7 +149,7 @@ export const getIndexerBalance = async ( throw new CheckoutError( err.message || 'InternalServerError | getTokensByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, - err, + { error: err }, ); } } @@ -172,7 +172,7 @@ export const getIndexerBalance = async ( throw new CheckoutError( err.message || 'InternalServerError | getNativeTokenByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, - err, + { error: err }, ); } } diff --git a/packages/checkout/sdk/src/config/remoteConfigFetcher.ts b/packages/checkout/sdk/src/config/remoteConfigFetcher.ts index 2845ee3caa..9a8da03228 100644 --- a/packages/checkout/sdk/src/config/remoteConfigFetcher.ts +++ b/packages/checkout/sdk/src/config/remoteConfigFetcher.ts @@ -46,8 +46,12 @@ export class RemoteConfigFetcher { if (response.data && typeof response.data !== 'object') { try { responseData = JSON.parse(response.data); - } catch (jsonError) { - throw new CheckoutError('Invalid configuration', CheckoutErrorType.API_ERROR); + } catch (err: any) { + throw new CheckoutError( + 'Invalid configuration', + CheckoutErrorType.API_ERROR, + { error: err }, + ); } } @@ -66,6 +70,7 @@ export class RemoteConfigFetcher { throw new CheckoutError( `Error: ${err.message}`, CheckoutErrorType.API_ERROR, + { error: err }, ); } @@ -87,6 +92,7 @@ export class RemoteConfigFetcher { throw new CheckoutError( `Error: ${err.message}`, CheckoutErrorType.API_ERROR, + { error: err }, ); } diff --git a/packages/checkout/sdk/src/connect/connect.ts b/packages/checkout/sdk/src/connect/connect.ts index 1ee5f3f1f8..9639c0c59c 100644 --- a/packages/checkout/sdk/src/connect/connect.ts +++ b/packages/checkout/sdk/src/connect/connect.ts @@ -26,6 +26,7 @@ export async function checkIsWalletConnected( 'Check wallet connection request failed', CheckoutErrorType.PROVIDER_REQUEST_FAILED_ERROR, { + error: err, rpcMethod: WalletAction.CHECK_CONNECTION, }, ); diff --git a/packages/checkout/sdk/src/errors/checkoutError.ts b/packages/checkout/sdk/src/errors/checkoutError.ts index 71f9d09ba0..8a70d41835 100644 --- a/packages/checkout/sdk/src/errors/checkoutError.ts +++ b/packages/checkout/sdk/src/errors/checkoutError.ts @@ -65,12 +65,14 @@ export class CheckoutError extends Error { public type: CheckoutErrorType; - public data?: { [key: string]: string }; + public data?: { [key: string]: any }; constructor( message: string, type: CheckoutErrorType, - data?: { [key: string]: string }, + data?: { + [key: string]: any + }, ) { super(message); this.message = message; diff --git a/packages/checkout/sdk/src/network/network.ts b/packages/checkout/sdk/src/network/network.ts index cdc8658214..fd6a17bcd8 100644 --- a/packages/checkout/sdk/src/network/network.ts +++ b/packages/checkout/sdk/src/network/network.ts @@ -181,6 +181,7 @@ export async function switchWalletNetwork( throw new CheckoutError( 'User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR, + { error: err }, ); } } else { diff --git a/packages/checkout/sdk/src/provider/validateProvider.ts b/packages/checkout/sdk/src/provider/validateProvider.ts index fe7494d3d2..db5345a3c9 100644 --- a/packages/checkout/sdk/src/provider/validateProvider.ts +++ b/packages/checkout/sdk/src/provider/validateProvider.ts @@ -54,6 +54,7 @@ export async function validateProvider( throw new CheckoutError( 'Unable to detect the web3Provider network', CheckoutErrorType.WEB3_PROVIDER_ERROR, + { error: err }, ); } diff --git a/packages/checkout/sdk/src/sdk.ts b/packages/checkout/sdk/src/sdk.ts index 951cc6ad26..33dd6997f8 100644 --- a/packages/checkout/sdk/src/sdk.ts +++ b/packages/checkout/sdk/src/sdk.ts @@ -140,7 +140,7 @@ export class Checkout { new CheckoutError( 'Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, - { message: err.message }, + { error: err }, ), ); } @@ -429,8 +429,12 @@ export class Checkout { let itemRequirements = []; try { itemRequirements = await getItemRequirementsFromRequirements(web3Provider, params.itemRequirements); - } catch (error) { - throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR); + } catch (err: any) { + throw new CheckoutError( + 'Failed to map item requirements', + CheckoutErrorType.ITEM_REQUIREMENTS_ERROR, + { error: err }, + ); } return await smartCheckout.smartCheckout( diff --git a/packages/checkout/sdk/src/smartCheckout/actions/signActions.test.ts b/packages/checkout/sdk/src/smartCheckout/actions/signActions.test.ts index deb8995e6d..9e641c670c 100644 --- a/packages/checkout/sdk/src/smartCheckout/actions/signActions.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/actions/signActions.test.ts @@ -107,9 +107,7 @@ describe('signActions', () => { expect(message).toEqual('An error occurred while executing the approval transaction'); expect(type).toEqual(CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR); - expect(data).toEqual({ - message: 'approval error', - }); + expect(data.error).toBeDefined(); }); }); @@ -207,9 +205,7 @@ describe('signActions', () => { expect(message).toEqual('An error occurred while executing the fulfillment transaction'); expect(type).toEqual(CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR); - expect(data).toEqual({ - message: 'fulfillment error', - }); + expect(data.error).toBeDefined(); }); }); @@ -281,9 +277,7 @@ describe('signActions', () => { expect(message).toEqual('An error occurred while signing the message'); expect(type).toEqual(CheckoutErrorType.SIGN_MESSAGE_ERROR); - expect(data).toEqual({ - message: 'sign message error', - }); + expect(data.error).toBeDefined(); }); }); }); diff --git a/packages/checkout/sdk/src/smartCheckout/actions/signActions.ts b/packages/checkout/sdk/src/smartCheckout/actions/signActions.ts index 3d525c5caf..305fb40d42 100644 --- a/packages/checkout/sdk/src/smartCheckout/actions/signActions.ts +++ b/packages/checkout/sdk/src/smartCheckout/actions/signActions.ts @@ -24,9 +24,7 @@ export const signApprovalTransactions = async ( throw new CheckoutError( 'An error occurred while executing the approval transaction', CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR, - { - message: err.message, - }, + { error: err }, ); } @@ -60,9 +58,7 @@ export const signFulfillmentTransactions = async ( throw new CheckoutError( 'An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, - { - message: err.message, - }, + { error: err }, ); } @@ -101,9 +97,7 @@ export const signMessage = async ( throw new CheckoutError( 'An error occurred while signing the message', CheckoutErrorType.SIGN_MESSAGE_ERROR, - { - message: err.message, - }, + { error: err }, ); } }; diff --git a/packages/checkout/sdk/src/smartCheckout/allowance/erc20.test.ts b/packages/checkout/sdk/src/smartCheckout/allowance/erc20.test.ts index f94addd19e..a004b970a5 100644 --- a/packages/checkout/sdk/src/smartCheckout/allowance/erc20.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/allowance/erc20.test.ts @@ -36,9 +36,9 @@ describe('allowance', () => { allowance: allowanceMock, }); - let message = ''; - let type = ''; - let data = {}; + let message; + let type; + let data; try { await getERC20Allowance( @@ -55,9 +55,7 @@ describe('allowance', () => { expect(message).toEqual('Failed to get the allowance for ERC20'); expect(type).toEqual(CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR); - expect(data).toEqual({ - contractAddress: 'OxERC20', - }); + expect(data.error).toBeDefined(); expect(allowanceMock).toBeCalledWith('0xADDRESS', '0xSEAPORT'); }); }); @@ -90,9 +88,9 @@ describe('allowance', () => { }, }); - let message = ''; - let type = ''; - let data = {}; + let message; + let type; + let data; try { await getERC20ApprovalTransaction( @@ -110,9 +108,8 @@ describe('allowance', () => { expect(message).toEqual('Failed to get the approval transaction for ERC20'); expect(type).toEqual(CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR); - expect(data).toEqual({ - contractAddress: 'OxERC20', - }); + expect(data.error).toBeDefined(); + expect(data.contractAddress).toEqual('OxERC20'); expect(approveMock).toBeCalledWith('0xSEAPORT', BigNumber.from(1)); }); }); diff --git a/packages/checkout/sdk/src/smartCheckout/allowance/erc20.ts b/packages/checkout/sdk/src/smartCheckout/allowance/erc20.ts index 7d26b2ce48..206756c84b 100644 --- a/packages/checkout/sdk/src/smartCheckout/allowance/erc20.ts +++ b/packages/checkout/sdk/src/smartCheckout/allowance/erc20.ts @@ -23,7 +23,7 @@ export const getERC20Allowance = async ( throw new CheckoutError( 'Failed to get the allowance for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, - { contractAddress }, + { contractAddress, error: err }, ); } }; @@ -46,11 +46,11 @@ export const getERC20ApprovalTransaction = async ( const approveTransaction = await contract.populateTransaction.approve(spenderAddress, amount); if (approveTransaction) approveTransaction.from = ownerAddress; return approveTransaction; - } catch { + } catch (err: any) { throw new CheckoutError( 'Failed to get the approval transaction for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, - { contractAddress }, + { contractAddress, error: err }, ); } }; diff --git a/packages/checkout/sdk/src/smartCheckout/allowance/erc721.test.ts b/packages/checkout/sdk/src/smartCheckout/allowance/erc721.test.ts index 68bdbe57b5..5549d30e81 100644 --- a/packages/checkout/sdk/src/smartCheckout/allowance/erc721.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/allowance/erc721.test.ts @@ -41,9 +41,9 @@ describe('erc721', () => { getApproved: getApprovedMock, }); - let message = ''; - let type = ''; - let data = {}; + let message; + let type; + let data; try { await getERC721ApprovedAddress( @@ -59,10 +59,9 @@ describe('erc721', () => { expect(message).toEqual('Failed to get approved address for ERC721'); expect(type).toEqual(CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR); - expect(data).toEqual({ - id: '0', - contractAddress: '0xERC721', - }); + expect(data.error).toBeDefined(); + expect(data.id).toEqual('0'); + expect(data.contractAddress).toEqual('0xERC721'); expect(getApprovedMock).toBeCalledWith(0); }); }); @@ -95,9 +94,9 @@ describe('erc721', () => { }, }); - let message = ''; - let type = ''; - let data = {}; + let message; + let type; + let data; try { await getApproveTransaction( @@ -115,12 +114,11 @@ describe('erc721', () => { expect(message).toEqual('Failed to get the approval transaction for ERC721'); expect(type).toEqual(CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR); - expect(data).toEqual({ - id: '0', - contractAddress: '0xERC721', - spenderAddress: '0xSEAPORT', - ownerAddress: '0xADDRESS', - }); + expect(data.error).toBeDefined(); + expect(data.id).toEqual('0'); + expect(data.contractAddress).toEqual('0xERC721'); + expect(data.spenderAddress).toEqual('0xSEAPORT'); + expect(data.ownerAddress).toEqual('0xADDRESS'); expect(approveMock).toBeCalledWith('0xSEAPORT', 0); }); }); @@ -148,10 +146,9 @@ describe('erc721', () => { isApprovedForAll: isApprovedForAllMock, }); - let message = ''; - let type = ''; - let data = {}; - + let message; + let type; + let data; try { await getERC721ApprovedForAll( mockProvider, @@ -167,11 +164,10 @@ describe('erc721', () => { expect(message).toEqual('Failed to check approval for all ERC721s of collection'); expect(type).toEqual(CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR); - expect(data).toEqual({ - ownerAddress: '0xADDRESS', - contractAddress: '0xERC721', - spenderAddress: '0xSEAPORT', - }); + expect(data.error).toBeDefined(); + expect(data.ownerAddress).toEqual('0xADDRESS'); + expect(data.contractAddress).toEqual('0xERC721'); + expect(data.spenderAddress).toEqual('0xSEAPORT'); expect(isApprovedForAllMock).toBeCalledWith('0xADDRESS', '0xSEAPORT'); }); }); diff --git a/packages/checkout/sdk/src/smartCheckout/allowance/erc721.ts b/packages/checkout/sdk/src/smartCheckout/allowance/erc721.ts index ba1e56c862..4576f1c50f 100644 --- a/packages/checkout/sdk/src/smartCheckout/allowance/erc721.ts +++ b/packages/checkout/sdk/src/smartCheckout/allowance/erc721.ts @@ -23,7 +23,12 @@ export const getERC721ApprovedForAll = async ( throw new CheckoutError( 'Failed to check approval for all ERC721s of collection', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, - { ownerAddress, contractAddress, spenderAddress }, + { + ownerAddress, + contractAddress, + spenderAddress, + error: err, + }, ); } }; @@ -50,7 +55,11 @@ export const getApproveTransaction = async ( 'Failed to get the approval transaction for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, { - id: id.toString(), contractAddress, spenderAddress, ownerAddress, + id: id.toString(), + contractAddress, + spenderAddress, + ownerAddress, + error: err, }, ); } @@ -74,7 +83,11 @@ export const getERC721ApprovedAddress = async ( throw new CheckoutError( 'Failed to get approved address for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, - { id: id.toString(), contractAddress }, + { + id: id.toString(), + contractAddress, + error: err, + }, ); } }; diff --git a/packages/checkout/sdk/src/smartCheckout/balanceCheck/balanceCheck.ts b/packages/checkout/sdk/src/smartCheckout/balanceCheck/balanceCheck.ts index 5c791f2703..23de4b70e5 100644 --- a/packages/checkout/sdk/src/smartCheckout/balanceCheck/balanceCheck.ts +++ b/packages/checkout/sdk/src/smartCheckout/balanceCheck/balanceCheck.ts @@ -45,10 +45,11 @@ const getTokenBalances = async ( return balances.filter( (balance) => tokenMap.get((balance.token.address || NATIVE).toLocaleLowerCase()), ) as TokenBalance[]; - } catch (error: any) { + } catch (err: any) { throw new CheckoutError( 'Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR, + { error: err }, ); } }; @@ -97,10 +98,11 @@ const getERC721Balances = async ( id: (itemRequirement as ERC721Item).id, }); }); - } catch (error: any) { + } catch (err: any) { throw new CheckoutError( 'Failed to get ERC721 balances', CheckoutErrorType.GET_ERC721_BALANCE_ERROR, + { error: err }, ); } diff --git a/packages/checkout/sdk/src/smartCheckout/buy/buy.test.ts b/packages/checkout/sdk/src/smartCheckout/buy/buy.test.ts index db2a6e37eb..1500871209 100644 --- a/packages/checkout/sdk/src/smartCheckout/buy/buy.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/buy/buy.test.ts @@ -664,20 +664,17 @@ describe('buy', () => { limit: BigNumber.from(constants.estimatedFulfillmentGasGwei), }, }; - let errorMessage; let errorType; let errorData; try { await buy(config, mockProvider, [order]); } catch (err: any) { errorType = err.type; - errorMessage = err.message; errorData = err.data; } - expect(errorMessage).toEqual('Error fetching fulfillment transaction'); expect(errorType).toEqual(CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR); - expect(errorData).toEqual({ message: 'Cannot estimate gas - not enough ERC20 approval' }); + expect(errorData.error).toBeDefined(); expect(smartCheckout).toBeCalledWith( config, @@ -1371,10 +1368,8 @@ describe('buy', () => { expect(message).toEqual('Error occurred while trying to fulfill the order'); expect(type).toEqual(CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR); - expect(data).toEqual({ - orderId: '1', - message: 'error from orderbook', - }); + expect(data.error).toBeDefined(); + expect(data.orderId).toEqual('1'); }); }); diff --git a/packages/checkout/sdk/src/smartCheckout/buy/buy.ts b/packages/checkout/sdk/src/smartCheckout/buy/buy.ts index 897137ee5c..3a8f18169e 100644 --- a/packages/checkout/sdk/src/smartCheckout/buy/buy.ts +++ b/packages/checkout/sdk/src/smartCheckout/buy/buy.ts @@ -136,8 +136,8 @@ export const buy = async ( 'An error occurred while getting the order listing', CheckoutErrorType.GET_ORDER_LISTING_ERROR, { + error: err, orderId: id, - message: err.message, }, ); } @@ -203,7 +203,7 @@ export const buy = async ( CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, { orderId: id, - message: err.message, + error: err, }, ); } @@ -293,9 +293,7 @@ export const buy = async ( throw new CheckoutError( 'Error fetching fulfillment transaction', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, - { - message: err.message, - }, + { error: err }, ); } if (overrides.waitFulfillmentSettlements) { diff --git a/packages/checkout/sdk/src/smartCheckout/cancel/cancel.test.ts b/packages/checkout/sdk/src/smartCheckout/cancel/cancel.test.ts index 2fa5c371b8..049e2a8437 100644 --- a/packages/checkout/sdk/src/smartCheckout/cancel/cancel.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/cancel/cancel.test.ts @@ -181,10 +181,8 @@ describe('cancel', () => { expect(message).toEqual('An error occurred while cancelling the order listing'); expect(type).toEqual(CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR); - expect(data).toEqual({ - orderId: '1', - message: 'An error occurred while cancelling the order listing', - }); + expect(data.error).toBeDefined(); + expect(data.orderId).toEqual('1'); }); }); }); diff --git a/packages/checkout/sdk/src/smartCheckout/cancel/cancel.ts b/packages/checkout/sdk/src/smartCheckout/cancel/cancel.ts index f9a0701903..e45b928d1a 100644 --- a/packages/checkout/sdk/src/smartCheckout/cancel/cancel.ts +++ b/packages/checkout/sdk/src/smartCheckout/cancel/cancel.ts @@ -49,7 +49,7 @@ export const cancel = async ( CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR, { orderId, - message: err.message, + error: err, }, ); } diff --git a/packages/checkout/sdk/src/smartCheckout/gas/gasCalculator.ts b/packages/checkout/sdk/src/smartCheckout/gas/gasCalculator.ts index f50e7eee89..1f433323e9 100644 --- a/packages/checkout/sdk/src/smartCheckout/gas/gasCalculator.ts +++ b/packages/checkout/sdk/src/smartCheckout/gas/gasCalculator.ts @@ -17,6 +17,7 @@ export const estimateGas = async ( throw new CheckoutError( 'Failed to estimate gas for transaction', CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT, + { error: err }, ); } }; diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts index 88c0f43714..0d94f08e98 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.ts @@ -68,6 +68,6 @@ describe('getBridgeFeeEstimate', () => { } expect(type).toEqual(CheckoutErrorType.BRIDGE_GAS_ESTIMATE_ERROR); - expect(data).toEqual({ message: 'error from gas estimator' }); + expect(data.error).toBeDefined(); }); }); diff --git a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts index a49787866d..95b4ee8448 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/bridge/getBridgeFeeEstimate.ts @@ -38,7 +38,7 @@ export const getBridgeFeeEstimate = async ( throw new CheckoutError( 'Error estimating gas for bridge', CheckoutErrorType.BRIDGE_GAS_ESTIMATE_ERROR, - { message: err.message }, + { error: err }, ); } }; diff --git a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts index b7b2597c05..e3470afae2 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.test.ts @@ -1122,7 +1122,6 @@ describe('routingCalculator', () => { try { await routingCalculator( config, - '0x123', balanceRequirements, availableRoutingOptions, @@ -1133,7 +1132,7 @@ describe('routingCalculator', () => { } expect(type).toEqual(CheckoutErrorType.PROVIDER_ERROR); - expect(data).toEqual({ message: 'Error from create readonly providers' }); + expect(data.error).toBeDefined(); }); describe('getSwapFundingStep', () => { diff --git a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts index 681548115c..82587fea45 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/routingCalculator.ts @@ -208,7 +208,7 @@ export const routingCalculator = async ( throw new CheckoutError( 'Error occurred while creating read only providers', CheckoutErrorType.PROVIDER_ERROR, - { message: err.message }, + { error: err }, ); } diff --git a/packages/checkout/sdk/src/smartCheckout/sell/sell.test.ts b/packages/checkout/sdk/src/smartCheckout/sell/sell.test.ts index 09f049d2b9..d9e45fd354 100644 --- a/packages/checkout/sdk/src/smartCheckout/sell/sell.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/sell/sell.test.ts @@ -530,11 +530,9 @@ describe('sell', () => { expect(message).toEqual('An error occurred while preparing the listing'); expect(type).toEqual(CheckoutErrorType.PREPARE_ORDER_LISTING_ERROR); - expect(data).toEqual({ - message: 'error from orderbook', - id, - collectionAddress: contractAddress, - }); + expect(data.error).toBeDefined(); + expect(data.id).toEqual(id); + expect(data.collectionAddress).toEqual(contractAddress); expect(smartCheckout).toBeCalledTimes(0); }); @@ -601,11 +599,9 @@ describe('sell', () => { expect(message).toEqual('An error occurred while preparing the listing'); expect(type).toEqual(CheckoutErrorType.PREPARE_ORDER_LISTING_ERROR); - expect(data).toEqual({ - message: 'error from provider', - id, - collectionAddress: contractAddress, - }); + expect(data.error).toBeDefined(); + expect(data.id).toEqual(id); + expect(data.collectionAddress).toEqual(contractAddress); expect(smartCheckout).toBeCalledTimes(0); }); @@ -1094,11 +1090,9 @@ describe('sell', () => { expect(message).toEqual('An error occurred while creating the listing'); expect(type).toEqual(CheckoutErrorType.CREATE_ORDER_LISTING_ERROR); - expect(data).toEqual({ - message: 'error from create listing', - collectionId, - collectionAddress: contractAddress, - }); + expect(data.error).toBeDefined(); + expect(data.collectionId).toEqual(collectionId); + expect(data.collectionAddress).toEqual(contractAddress); expect(smartCheckout).toBeCalledTimes(1); expect(signMessage).toBeCalledTimes(1); diff --git a/packages/checkout/sdk/src/smartCheckout/sell/sell.ts b/packages/checkout/sdk/src/smartCheckout/sell/sell.ts index 46e73aa5ff..f25eaf1d23 100644 --- a/packages/checkout/sdk/src/smartCheckout/sell/sell.ts +++ b/packages/checkout/sdk/src/smartCheckout/sell/sell.ts @@ -134,7 +134,7 @@ export const sell = async ( 'An error occurred while preparing the listing', CheckoutErrorType.PREPARE_ORDER_LISTING_ERROR, { - message: err.message, + error: err, id: sellToken.id, collectionAddress: sellToken.collectionAddress, }, @@ -224,7 +224,7 @@ export const sell = async ( 'An error occurred while creating the listing', CheckoutErrorType.CREATE_ORDER_LISTING_ERROR, { - message: err.message, + error: err, collectionId: sellToken.id, collectionAddress: sellToken.collectionAddress, }, diff --git a/packages/checkout/sdk/src/transaction/transaction.ts b/packages/checkout/sdk/src/transaction/transaction.ts index d0b820c42a..22b17a1a7d 100644 --- a/packages/checkout/sdk/src/transaction/transaction.ts +++ b/packages/checkout/sdk/src/transaction/transaction.ts @@ -31,23 +31,27 @@ export const sendTransaction = async ( throw new CheckoutError( err.message, CheckoutErrorType.INSUFFICIENT_FUNDS, + { error: err }, ); } if (err.code === ethers.errors.ACTION_REJECTED) { throw new CheckoutError( err.message, CheckoutErrorType.USER_REJECTED_REQUEST_ERROR, + { error: err }, ); } if (err.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) { throw new CheckoutError( err.message, CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT, + { error: err }, ); } throw new CheckoutError( err.message, CheckoutErrorType.TRANSACTION_FAILED, + { error: err }, ); } };