( overwriteError: Partial<Record<ContractErrorCode, () => Promise<string> | string>> )
| 20 | * You can provide an optional mapping of ContractErrorCode to custom error messages. |
| 21 | */ |
| 22 | export function parseContractError( |
| 23 | overwriteError: Partial<Record<ContractErrorCode, () => Promise<string> | string>> |
| 24 | ): (rawError: any) => Promise<never> { |
| 25 | return async (rawError: any) => { |
| 26 | const cErr = mapContractError(rawError); |
| 27 | const getOverwriteMessage = overwriteError[cErr.revertCode as ContractErrorCode]; |
| 28 | if (getOverwriteMessage) { |
| 29 | let message = cErr.message; |
| 30 | try { |
| 31 | message = await getOverwriteMessage(); |
| 32 | } catch (e) { |
| 33 | // Do nothing |
| 34 | } |
| 35 | |
| 36 | throw new Error(message, {cause: rawError}); |
| 37 | } |
| 38 | if (cErr.message) { |
| 39 | throw new Error(cErr.message, {cause: rawError}); |
| 40 | } |
| 41 | throw rawError; |
| 42 | }; |
| 43 | } |
no test coverage detected