# Error Handling for Proxy Contracts in web3 using .error

**URL:** <https://forum.openzeppelin.com/t/error-handling-for-proxy-contracts-in-web3-using-error/5607>\
**Category:** Upgrades\
**Created:** [January 30, 2021, 3:32pm UTC](https://forum.openzeppelin.com/t/error-handling-for-proxy-contracts-in-web3-using-error/5607 "2021-01-30T15:32:16Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [February 2, 2021, 6:49am UTC](https://forum.openzeppelin.com/t/error-handling-for-proxy-contracts-in-web3-using-error/5607/3 "2021-02-02T06:49:42Z")

</div>

Hi @cjd9s,

I am not familiar with error handling in web3.

I recommend creating a simple example that demonstrates the problem such as modifying the following (from: [OpenZeppelin Upgrades: Step by Step Tutorial for Truffle](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-truffle/3579)).

## Box.sol

```auto
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
 
contract Box {
    uint256 private value;
 
    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);
 
    // Stores a new value in the contract
    function store(uint256 newValue) public {
        require(newValue > 0, "Box: store non-zero numbers");
        value = newValue;
        emit ValueChanged(newValue);
    }
 
    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

```

## Box.test.js

```auto
// test/Box.test.js
// Load dependencies
const { expect } = require('chai');

const {
    BN, // Big Number support
    constants, // Common constants, like the zero address and largest integers
    expectEvent, // Assertions for emitted events
    expectRevert, // Assertions for transactions that should fail
  } = require('@openzeppelin/test-helpers');
 
// Load compiled artifacts
const Box = artifacts.require('Box');
 
// Start test block
contract('Box', function () {
  beforeEach(async function () {
    // Deploy a new Box contract for each test
    this.box = await Box.new();
  });

  it('non-zero number cannot be stored', async function () {
    // Store an invalid value
    await expectRevert(this.box.store(0), 'Box: store non-zero numbers');
  });
});

```

## Box.proxy.test.js

```auto
// test/Box.proxy.test.js
// Load dependencies
const { expect } = require('chai');

const {
    BN, // Big Number support
    constants, // Common constants, like the zero address and largest integers
    expectEvent, // Assertions for emitted events
    expectRevert, // Assertions for transactions that should fail
  } = require('@openzeppelin/test-helpers');

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
 
// Load compiled artifacts
const Box = artifacts.require('Box');
 
// Start test block
contract('Box (proxy)', function () {
  beforeEach(async function () {
    // Deploy a new Box contract for each test
    this.box = await deployProxy(Box, [42], {initializer: 'store'});
  });
 
  // Test case
  it('non-zero number cannot be stored', async function () {
    // Store an invalid value
    await expectRevert(this.box.store(0), 'Box: store non-zero numbers');
  });
});

```

```auto
$ npx truffle test

Compiling your contracts...
===========================
> Compiling ./contracts/Box.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--9290-Ur5S92vRB2B2
> Compiled successfully using:
   - solc: 0.7.3+commit.9bfce1f6.Emscripten.clang

  Contract: Box (proxy)
    ✓ non-zero number cannot be stored (67ms)

  Contract: Box
    ✓ non-zero number cannot be stored (54ms)

  2 passing (3s)

```

---

_[View the full topic](https://forum.openzeppelin.com/t/error-handling-for-proxy-contracts-in-web3-using-error/5607)._
