RemoteErrorResponse

Trait RemoteErrorResponse 

Source
pub trait RemoteErrorResponse {
    // Required methods
    fn error_code(&self) -> u32;
    fn error_message(&self) -> String;
}
Expand description

This trait should me implemented by the Error type returned in your server’s procedures

§Example

use dcl_rpc::rpc_protocol::{RemoteError, RemoteErrorResponse};
pub enum MyEnumOfErrors {
    EntityNotFound,
    DbError
}

impl RemoteErrorResponse for MyEnumOfErrors {
    fn error_code(&self) -> u32 {
        match self {
            Self::EntityNotFound => 404,
            Self::DbError => 500
        }
    }
     
    fn error_message(&self) -> String {
        match self {
            Self::EntityNotFound => "The entity wasn't found".to_string(),
            Self::DbError => "Internal Server Error".to_string()
        }
    }
}

let error: RemoteError = MyEnumOfErrors::EntityNotFound.into();
assert_eq!(error.error_code, 404);
assert_eq!(error.error_message, "The entity wasn't found")

Required Methods§

Implementors§