sheave_client/handlers/
error_response.rs

1use std::{
2    error::Error,
3    fmt::{
4        Display,
5        Formatter,
6        Result as FormatResult
7    },
8    io::{
9        Error as IOError,
10        ErrorKind
11    }
12};
13use sheave_core::messages::amf::v0::Object;
14
15/// An error that some _error command got sent from the server.
16#[derive(Debug)]
17pub struct ErrorResponse(Object);
18
19impl ErrorResponse {
20    /// Constructs this error.
21    pub fn new(information: Object) -> Self {
22        Self(information)
23    }
24}
25
26impl Display for ErrorResponse {
27    fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
28        writeln!(f, "_error response got handled.\ninformation: {:?}", self.0)
29    }
30}
31
32impl Error for ErrorResponse {}
33
34/// A utility function of constructing an `ErrorResponse` error.
35pub fn error_response(information: Object) -> IOError {
36    IOError::new(
37        ErrorKind::InvalidData,
38        ErrorResponse(information)
39    )
40}