Skip to content

Commit

Permalink
remove asref
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed May 7, 2024
1 parent b79ece8 commit 8cfa0da
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions examples/error-handling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,16 @@
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::near;
use near_sdk::contract_error;
use near_sdk::FunctionError;

#[contract_error]
enum MyErrorEnum {X}
impl AsRef<str> for MyErrorEnum {
fn as_ref(&self) -> &str {
match self {
MyErrorEnum::X => "X",
}
}
}

#[contract_error]
struct MyErrorStruct {
x: u32,
}

#[derive(Debug)]
#[near(serializers=[json])]
enum AnotherError {X}
impl AsRef<str> for AnotherError {
fn as_ref(&self) -> &str {
match self {
AnotherError::X => "X",
}
}
}

// Define the contract structure
#[near(contract_state)]
#[derive(Default)]
Expand All @@ -40,10 +23,10 @@ pub struct Contract {
#[near]
impl Contract {
#[handle_result]
pub fn inc_handle_result(&mut self, is_error: bool) -> Result<u32, AnotherError> {
pub fn inc_handle_result(&mut self, is_error: bool) -> Result<u32, &'static str> {
self.value += 1;
if is_error {
return Err(AnotherError::X);
return Err("error in inc_handle_result");
} else {
return Ok(self.value);
}
Expand Down

0 comments on commit 8cfa0da

Please sign in to comment.