/// Send the given error as response.
Send the given error as response.
Send the given error as response .
pub async fn error<D, M>(
        &self,
        id: Option<envelope::RequestId>,
        code: envelope::Code,
        message: M,
        data: Option<D>,
    ) -> Result<()>
    where
        D: serde::Serialize,
        M: fmt::Display,
    {
        let response = envelope::ResponseMessage {
            jsonrpc: crate::envelope::V2,
            id,
            result: None::<()>,
            error: Some(envelope::ResponseError {
                code,
                message: message.to_string(),
                data,
            }),
        };
        let mut bytes = serde_json::to_vec(&response)?;
        self.write_response(&mut bytes).await?;
        Ok(())
    }
pub async fn error < D , M > ( & self , id : Option < envelope :: RequestId > , code : envelope :: Code , message : M , data : Option < D > , ) -> Result < ( ) > where D : serde :: Serialize , M : fmt :: Display , { let response = envelope :: ResponseMessage { jsonrpc : crate :: envelope :: V2 , id , result : None :: < ( ) > , error : Some ( envelope :: ResponseError { code , message : message . to_string ( ) , data , } ) , } ; let mut bytes = serde_json :: to_vec ( & response ) ? ; self . write_response ( & mut bytes ) . await ? ; Ok ( ( ) ) }
Send the given error as response.
Send the given error as response .
&self
id
Option<envelope::RequestId>
code
envelope::Code
message
M
data
Option<D>