actix_msgpack/
msgpack_error.rs1use actix_web::{error::PayloadError, HttpResponse, ResponseError};
2use derive_more::Display;
3use rmp_serde::{decode::Error as RmpSerdeDecodeError, encode::Error as RmpSerdeEncodeError};
4
5#[derive(Debug, Display)]
6pub enum MsgPackError {
7 #[display(fmt = "Payload size is bigger than limit")]
9 Overflow,
10
11 #[display(fmt = "Content type error")]
13 ContentType,
14
15 #[display(fmt = "Deserialize error: {_0}")]
17 Deserialize(RmpSerdeDecodeError),
18
19 #[display(fmt = "Serialize error: {_0}")]
21 Serialize(RmpSerdeEncodeError),
22
23 #[display(fmt = "Error that occur during reading payload: {_0}")]
25 Payload(PayloadError),
26}
27
28impl ResponseError for MsgPackError {
29 fn error_response(&self) -> HttpResponse {
30 match *self {
31 MsgPackError::Overflow => HttpResponse::PayloadTooLarge().into(),
32 _ => HttpResponse::BadRequest().into(),
33 }
34 }
35}
36
37impl From<PayloadError> for MsgPackError {
38 fn from(err: PayloadError) -> MsgPackError {
39 MsgPackError::Payload(err)
40 }
41}
42
43impl From<RmpSerdeDecodeError> for MsgPackError {
44 fn from(err: RmpSerdeDecodeError) -> MsgPackError {
45 MsgPackError::Deserialize(err)
46 }
47}