medea_control_api_proto/grpc/convert/
mod.rs1mod api;
6mod callback;
7
8use derive_more::with_trait::{Display, Error, From};
9
10use super::CallbackUrlParseError;
11use crate::{
12 control::ParseFidError, endpoint::web_rtc_play::LocalSrcUriParseError,
13};
14
15#[derive(Debug, Display, Error, From)]
19pub enum ProtobufError {
20 #[display("Source URI parse error: {_0}")]
27 LocalSrcUriParseErr(LocalSrcUriParseError),
28
29 #[display("`{_1}` media element expected to be of type `{_0}`")]
33 #[from(ignore)]
34 ExpectedElement(&'static str, Box<str>),
35
36 #[display("Expected media element, but none specified")]
40 NoElement,
41
42 #[display("Expected media element for `{_0}`, but none specified")]
47 #[from(ignore)]
48 NoElementForId(#[error(not(source))] Box<str>),
49
50 #[display("gRPC callback URL parse error: {_0}")]
54 CallbackUrlParseErr(CallbackUrlParseError),
55
56 #[display(
61 "`Element(id: {_0})` specifies field `{_1}` with invalid duration"
62 )]
63 #[from(ignore)]
64 InvalidDuration(Box<str>, &'static str),
65
66 #[display("FID parse error: {_0}")]
70 ParseFidErr(ParseFidError),
71
72 #[display("`DateTime` parse error: {_0}")]
76 TimeParseErr(time::error::Parse),
77
78 #[display("API call is unimplemented")]
80 Unimplemented,
81}
82
83impl From<ProtobufError> for tonic::Status {
84 fn from(err: ProtobufError) -> Self {
85 match &err {
86 ProtobufError::LocalSrcUriParseErr(_)
87 | ProtobufError::ExpectedElement(_, _)
88 | ProtobufError::NoElement
89 | ProtobufError::NoElementForId(_)
90 | ProtobufError::CallbackUrlParseErr(_)
91 | ProtobufError::InvalidDuration(_, _)
92 | ProtobufError::ParseFidErr(_)
93 | ProtobufError::TimeParseErr(_) => {
94 Self::invalid_argument(err.to_string())
95 }
96 ProtobufError::Unimplemented => {
97 Self::unimplemented(err.to_string())
98 }
99 }
100 }
101}