94 lines
2.1 KiB
Rust
94 lines
2.1 KiB
Rust
use std::fmt::Display;
|
|
|
|
use matrix_sdk::{self, encryption::CryptoStoreError, HttpError, IdParseError, StoreError};
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum ClientError {
|
|
#[error("client error: {msg}")]
|
|
Generic { msg: String },
|
|
}
|
|
|
|
impl ClientError {
|
|
fn new<E: Display>(error: E) -> Self {
|
|
Self::Generic { msg: error.to_string() }
|
|
}
|
|
}
|
|
|
|
impl From<anyhow::Error> for ClientError {
|
|
fn from(e: anyhow::Error) -> ClientError {
|
|
ClientError::Generic { msg: format!("{e:#}") }
|
|
}
|
|
}
|
|
|
|
impl From<matrix_sdk::Error> for ClientError {
|
|
fn from(e: matrix_sdk::Error) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
impl From<StoreError> for ClientError {
|
|
fn from(e: StoreError) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
impl From<CryptoStoreError> for ClientError {
|
|
fn from(e: CryptoStoreError) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
impl From<HttpError> for ClientError {
|
|
fn from(e: HttpError) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
impl From<IdParseError> for ClientError {
|
|
fn from(e: IdParseError) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
impl From<serde_json::Error> for ClientError {
|
|
fn from(e: serde_json::Error) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
impl From<url::ParseError> for ClientError {
|
|
fn from(e: url::ParseError) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
impl From<mime::FromStrError> for ClientError {
|
|
fn from(e: mime::FromStrError) -> Self {
|
|
Self::new(e)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error, uniffi::Error)]
|
|
#[uniffi(flat_error)]
|
|
pub enum RoomError {
|
|
#[error("Invalid attachment data")]
|
|
InvalidAttachmentData,
|
|
#[error("Invalid attachment mime type")]
|
|
InvalidAttachmentMimeType,
|
|
#[error("Timeline unavailable")]
|
|
TimelineUnavailable,
|
|
#[error("Invalid thumbnail data")]
|
|
InvalidThumbnailData,
|
|
#[error("Failed sending attachment")]
|
|
FailedSendingAttachment,
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error, uniffi::Error)]
|
|
#[uniffi(flat_error)]
|
|
pub enum TimelineError {
|
|
#[error("Required value missing from the media info")]
|
|
MissingMediaInfoField,
|
|
#[error("Media info field invalid")]
|
|
InvalidMediaInfoField,
|
|
}
|