diff --git a/packages/common/src/httpRequests.ts b/packages/common/src/httpRequests.ts index aa828998d..6368ac576 100644 --- a/packages/common/src/httpRequests.ts +++ b/packages/common/src/httpRequests.ts @@ -40,39 +40,32 @@ export async function sendRequest({ url, method, body, headers = {} }: HttpRe if (jsonResponse && jsonResponse.hasOwnProperty('result')) { return jsonResponse as T } + // else } + const errorObject = { code: response.status, message: response.statusText } + if (jsonResponse?.error) { - // Review: below works well to catch errors for paymaster - /*const error = jsonResponse.error - const errorObject = { - code: error.code, - message: error.message + if (typeof jsonResponse.error === 'string') { + const error = jsonResponse.error + errorObject.code = response.status + errorObject.message = error + throw errorObject + } else if (typeof jsonResponse.error === 'object') { + const error = jsonResponse.error + errorObject.code = error?.code + errorObject.message = error?.message + throw errorObject } - throw errorObject*/ - // Review: Below works well for bundler - throw new Error(jsonResponse.error) } if (jsonResponse?.message) { - throw new Error(jsonResponse.message) + errorObject.message = jsonResponse.message + throw errorObject } if (jsonResponse?.msg) { - throw new Error(jsonResponse.msg) - } - if (jsonResponse?.data) { - throw new Error(jsonResponse.data) - } - if (jsonResponse?.detail) { - throw new Error(jsonResponse.detail) - } - if (jsonResponse?.message) { - throw new Error(jsonResponse.message) - } - if (jsonResponse?.nonFieldErrors) { - throw new Error(jsonResponse.nonFieldErrors) - } - if (jsonResponse?.delegate) { - throw new Error(jsonResponse.delegate) + errorObject.message = jsonResponse.msg + throw errorObject } + throw new Error( 'Unknown Error: Raise an issue here https://github.com/bcnmy/biconomy-client-sdk/issues with reproduction steps' ) diff --git a/packages/paymaster/src/BiconomyPaymaster.ts b/packages/paymaster/src/BiconomyPaymaster.ts index de386b8ff..afab4f4dd 100644 --- a/packages/paymaster/src/BiconomyPaymaster.ts +++ b/packages/paymaster/src/BiconomyPaymaster.ts @@ -17,11 +17,22 @@ import { BigNumberish, BigNumber, ethers } from 'ethers' import { ERC20_ABI } from './constants' import { IHybridPaymaster } from './interfaces/IHybridPaymaster' +const defaultPaymasterConfig: PaymasterConfig = { + paymasterUrl: '', + strictMode: true // Set your desired default value for strictMode here +} /** * @dev Hybrid - Generic Gas Abstraction paymaster */ export class BiconomyPaymaster implements IHybridPaymaster { - constructor(readonly paymasterConfig: PaymasterConfig) {} + paymasterConfig: PaymasterConfig + constructor(config: PaymasterConfig) { + const mergedConfig: PaymasterConfig = { + ...defaultPaymasterConfig, + ...config + } + this.paymasterConfig = mergedConfig + } /** * @dev Prepares the user operation by resolving properties and converting certain values to hexadecimal format. @@ -59,7 +70,8 @@ export class BiconomyPaymaster implements IHybridPaymaster, paymasterServiceData: FeeQuotesOrDataDto ): Promise { - userOp = await this.prepareUserOperation(userOp) + try { + userOp = await this.prepareUserOperation(userOp) + } catch (err) { + Logger.log('Error in prepareUserOperation ', err) + throw err + } let mode = null const calculateGasLimits = paymasterServiceData.calculateGasLimits @@ -190,15 +214,36 @@ export class BiconomyPaymaster implements IHybridPaymaster, paymasterServiceData?: SponsorUserOperationDto // mode is necessary. partial context of token paymaster or verifying ): Promise { + Logger.log('calculateGasLimits is ', paymasterServiceData?.calculateGasLimits) try { - Logger.log('calculateGasLimits is ', paymasterServiceData?.calculateGasLimits) userOp = await this.prepareUserOperation(userOp) + } catch (err) { + Logger.log('Error in prepareUserOperation ', err) + throw err + } + try { const response: JsonRpcResponse = await sendRequest({ url: `${this.paymasterConfig.paymasterUrl}`, method: HttpMethod.Post, @@ -241,13 +291,24 @@ export class BiconomyPaymaster implements IHybridPaymaster