Errors Rust

This project is to map errors using a wrapper, this is useful when you need to map errors between layers on an API rest to avoid having to use panic or specific errors from a framework.

How to use it

You just need to import this project into yours and use like this: ``` use errors_rust::errors::generic::{RustError, RustErrorParams};

struct Test {}

impl Test { pub fn method1(someparam: Option) -> Result { if someparam.isnone() { return Err(RustError::fromstring("Error Method 1")); } Ok(someparam.unwrap()) } pub fn method2(someparam: Option) -> Result { if someparam.isnone() { return Err(RustError::fromparams(RustErrorParams{ code: Some(10), description: Some(String::from("Error Method 2")), message: Some(String::from("Message From Error Method 2")) })); } Ok(someparam.unwrap()) } pub fn method3(someparam: Option) -> Result { if someparam.isnone() { return Err(RustError::new(Some(10), Some(String::from("Message From Error Method 3")), Some(String::from("Error Method 3")))); } Ok(some_param.unwrap()) } }

fn main() { let mut result = Test::method1(None); if result.iserr() { let rusterror = result.unwraperr(); println!("Error Code: {} Error Description: {} Error Message {}", rusterror.code, rusterror.description, rusterror.message); } result = Test::method2(None); if result.iserr() { let rusterror = result.unwraperr(); println!("Error Code: {} Error Description: {} Error Message {}", rusterror.code, rusterror.description, rusterror.message); } result = Test::method3(None); if result.iserr() { let rusterror = result.unwraperr(); println!("Error Code: {} Error Description: {} Error Message {}", rusterror.code, rusterror.description, rust_error.message); } } ```

Available on crates.io

You can use this dependency on your Cargo.toml like this: toml [dependencies.errors_rust] version = "0.1.0"