Skip to content

Commit

Permalink
docs: add call response error handling section (#824)
Browse files Browse the repository at this point in the history
add error handling section for the Call response page in the docs
  • Loading branch information
sarahschwartz authored Feb 6, 2023
1 parent 4e92144 commit 0198c43
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/src/calling-contracts/call-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ Where `value` will hold the value returned by its respective contract method, re

- `receipts` will hold all [receipts](https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#receipt) generated by that specific contract call.
- `gas_used` is the amount of gas it consumed by the contract call.

## Error handling

You can use the `is_ok` and `is_err` methods to check if a contract call `Result` is ok or contains an error. These methods will return either `true` or `false`.

```rust, ignore
let is_ok = response.is_ok();
let is_error = response.is_err();
```

If `is_err` returns `true`, you can use the `unwrap_err` method to unwrap the error message.

```rust, ignore
if response.is_err() {
let err = response.unwrap_err();
println!("ERROR: {:?}", err);
};
```

0 comments on commit 0198c43

Please sign in to comment.