use thiserror::Error;
#[derive(Error, Debug)]
pub enum PlatformError {
#[error("Platform error: {0}")]
Platform(String),
#[error("Not supported: {0}")]
NotSupported(String),
#[error("Asset not found: {0}")]
AssetNotFound(String),
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Business error: code {0}")]
BusinessError(u32),
#[error("Callback dropped")]
CallbackDropped,
#[error("Page chrome presenter not mounted")]
PresenterUnavailable,
}
pub const PRESENTER_UNAVAILABLE_CODE: u32 = 1001;
#[cfg(any(target_os = "android", target_env = "ohos"))]
pub(crate) fn unmounted_presenter_or(error: PlatformError) -> PlatformError {
match error {
PlatformError::BusinessError(PRESENTER_UNAVAILABLE_CODE) => {
PlatformError::PresenterUnavailable
}
other => other,
}
}
pub type PlatformResult<T> = Result<T, PlatformError>;
#[cfg(target_os = "android")]
impl From<jni::errors::Error> for PlatformError {
fn from(value: jni::errors::Error) -> Self {
PlatformError::Platform(format!("JNI error: {}", value))
}
}