From 4a403eef75ee7ea0b5c21b1ae1bdac4988843645 Mon Sep 17 00:00:00 2001 From: "Shiv Bhonde | shivbhonde.eth" Date: Thu, 7 Dec 2023 21:40:18 +0530 Subject: [PATCH] Check cause?.data on getParsedError (#649) --- .../nextjs/components/scaffold-eth/Contract/utilsContract.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx b/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx index 0c7d662ad..9da4b1edd 100644 --- a/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx +++ b/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx @@ -25,9 +25,9 @@ const getParsedError = (e: any): string => { message = e.details; } else if (e.shortMessage) { message = e.shortMessage; - const cause = e.cause as { data?: DecodeErrorResultReturnType }; + const cause = e.cause as { data?: DecodeErrorResultReturnType } | undefined; // if its not generic error, append custom error name and its args to message - if (cause.data && cause.data?.abiItem?.name !== "Error") { + if (cause?.data && cause.data?.abiItem?.name !== "Error") { const customErrorArgs = cause.data.args?.toString() ?? ""; message = `${message.replace(/reverted\.$/, "reverted with following reason:")}\n${ cause.data.errorName