(rawErrorMsg: any)
| 6 | export type ContractErrorCode = keyof typeof contractErrorCodes; |
| 7 | |
| 8 | function mapContractError(rawErrorMsg: any): {revertCode?: ContractErrorCode; message?: string} { |
| 9 | const revertCode = Object.keys(contractErrorCodes).find( |
| 10 | (key) => rawErrorMsg.toString().match(`reverted: ${key}`) || (rawErrorMsg as any).reason === key |
| 11 | ) as ContractErrorCode; |
| 12 | return { |
| 13 | revertCode, |
| 14 | message: revertCode ? contractErrorCodes[revertCode] : undefined, |
| 15 | }; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Parse a raw error from a contract call and throw a more descriptive error message if available. |
no test coverage detected