Skip to main content

citadel_sdk/media/
error.rs

1//! `MediaError` → `NetworkError` mapping. A `From` impl is impossible here
2//! (orphan rule: both types are foreign), so the conversion is a function plus
3//! a result-extension trait.
4use citadel_io::ErrorCode;
5use citadel_media::MediaError;
6use citadel_proto::prelude::NetworkError;
7
8/// Maps a [`MediaError`] onto the registry: config errors become
9/// `MediaConfigInvalid`, everything else `MediaFrameRejected`.
10pub fn from_media_error(err: MediaError) -> NetworkError {
11    match err {
12        MediaError::InvalidConfig(_) => citadel_io::error!(ErrorCode::MediaConfigInvalid, err),
13        _ => citadel_io::error!(ErrorCode::MediaFrameRejected, err),
14    }
15}
16
17/// `Result<T, MediaError>` → `Result<T, NetworkError>`.
18pub trait MediaResultExt<T> {
19    fn net(self) -> Result<T, NetworkError>;
20}
21
22impl<T> MediaResultExt<T> for Result<T, MediaError> {
23    fn net(self) -> Result<T, NetworkError> {
24        self.map_err(from_media_error)
25    }
26}