Handling error validation

Hi guys. I made a contract and mint function with some validation like:
require(balanceOf(_to) < 2, "ERC721: Each wallet address can only mint 1 NFT");

but when i run mint function from javascript, i can't catch the error to show. The error i got is:

Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x6e738787e0442fa4dd70b17098be60c41a4c366692eabaddbc8badb006efd320",
  "blockNumber": 11217592,
  "contractAddress": null,
  "cumulativeGasUsed": 5696103,
  "effectiveGasPrice": 2500001856,
  "from": "0x33915624c65aab6ab055dcb8037502515ddb082c",
  "gasUsed": 26666,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": "0xe687874da5b4126e3d2f13fd713d14068831bb0a",
  "transactionHash": "0xcb737b4a6646618f756047caa380e492e585037b60286998381bc56b0769dcc5",
  "transactionIndex": 12,
  "type": "0x2",
  "events": {}
}
    at Object.TransactionError (/Users/mahes.sawira/Documents/GitHub/codespade-nft/node_modules/web3-core-helpers/lib/errors.js:87:21)
    at Object.TransactionRevertedWithoutReasonError (/Users/mahes.sawira/Documents/GitHub/codespade-nft/node_modules/web3-core-helpers/lib/errors.js:98:21)
    at /Users/mahes.sawira/Documents/GitHub/codespade-nft/node_modules/web3-core-method/lib/index.js:396:57
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  receipt: {
    blockHash: '0x6e738787e0442fa4dd70b17098be60c41a4c366692eabaddbc8badb006efd320',
    blockNumber: 11217592,
    contractAddress: null,
    cumulativeGasUsed: 5696103,
    effectiveGasPrice: 2500001856,
    from: '0x33915624c65aab6ab055dcb8037502515ddb082c',
    gasUsed: 26666,
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    to: '0xe687874da5b4126e3d2f13fd713d14068831bb0a',
    transactionHash: '0xcb737b4a6646618f756047caa380e492e585037b60286998381bc56b0769dcc5',
    transactionIndex: 12,
    type: '0x2',
    events: {}
  }
}

does anyone knows how to gracefully handle error validation? is what i did in the sol wrong?

Hey @mahes_sawira, have you consider using https://tenderly.co/, it is great for testing, debugging, and simulating Smart Contracts.

It can help you understanding exactly in which line of code the contract throw the error, helping you debug what is wrong.

Thought it would help you debug your error and assist you going forward with future errors.